x = [3, 2, 3, 3, 2, 8]
k = 8

def count_min_length_subarrays(x, k):
    # Maps prefix_sum -> list of indices where it occurred
    # (Since we want all valid windows, we track all occurrences)
    prefix_map = {0: [-1]} 
    current_sum = 0
    
    min_len = float('inf')
    count = 0
    
    for index, value in enumerate(x):
        current_sum += value
        target = current_sum - k
        
        # If the complement prefix sum exists, we found valid subarrays
        if target in prefix_map:
            for start_index in prefix_map[target]:
                length = index - start_index
                
                if length < min_len:
                    min_len = length
                    count = 1  # Reset count for the new strictly smaller minimum length
                elif length == min_len:
                    count += 1 # Increment count for matching the current minimum length
        
        # Record the current prefix sum index
        if current_sum not in prefix_map:
            prefix_map[current_sum] = []
        prefix_map[current_sum].append(index)
        
    return min_len, count

min_length, frequency = count_min_length_subarrays(x, k)
print(f"Minimum Length: {min_length}")
print(f"Count of Minimum Length Subarrays: {frequency}")
