#K74877. Longest Subarray with Equal Number of Even and Odd Numbers

    ID: 34295 Type: Default 1000ms 256MiB

Longest Subarray with Equal Number of Even and Odd Numbers

Longest Subarray with Equal Number of Even and Odd Numbers

Given an array of integers, find the length of the longest contiguous subarray that contains an equal number of even and odd numbers. Formally, for a subarray A[i...j], it should satisfy:

$$count_{even}(A[i...j]) = count_{odd}(A[i...j])$$

If there is no such subarray, output 0.

Note: A contiguous subarray is a sequence of elements from the array with no gaps. The input is provided via standard input and the answer should be printed to standard output.

inputFormat

The first line contains an integer n representing the number of elements in the array. The second line contains n space-separated integers.

outputFormat

Output a single integer representing the length of the longest contiguous subarray that has an equal number of even and odd numbers.

## sample
6
1 2 3 4 5 6
6