A coin-flip experiment is logged as a sequence of n outcomes, each 0 (tails) or 1 (heads). Count how many contiguous subarrays contain exactly as many 0s as 1s. A subarray is a run of consecutive entries, and two subarrays that occupy different index ranges are counted separately even if their contents match.
Input format
Line 1: an integer n.
Line 2: n space-separated integers, each 0 or 1.
Output format
A single integer: the number of contiguous subarrays with equal counts of 0 and 1.
Constraints
- 1 <= n <= 40
- Each entry is 0 or 1.