LogiQuest

423. Longest Equal 0s and 1s

MediumPrefix SumHash Map

The array has only 0s and 1s. Print the length of the longest contiguous subarray with equal numbers of 0s and 1s.

Input format

Line 1: n Line 2: n bits

Output format

The length.

Example 1

Input

2
0 1

Output

2

Example 2

Input

3
0 1 0

Output

2

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…