You are given a string s consisting only of characters 0 and 1. A substring [l, r]of s is a string slsl + 1sl + 2... sr, and its length equals to r - l + 1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to determine the length of the longest balanced substring of s.
Input
The first line contains n (1 ≤ n ≤ 100000) — the number of characters in s.
The second line contains a string s consisting of exactly n characters. Only characters 0 and 1 can appear in s.
Output
If there is no non-empty balanced substring in s, print 0. Otherwise, print the length of the longest balanced substring.
Examples
Input
8 11010111
Output
4
Input
3 111
Output
0
Note
In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring.
题意:
如果子串中0的个数与1的个数相等的话 就说这个子串平衡
求 最长平衡子串的长度
这个问题可以转化成,最长子序列问题。
不知道怎么处理,后来听说 把0转化成-1,这样就可以求子序列为0时的最长长度。
有才的网友,借用map,因为map不能重复插入,第一次插入的一定是第一次出现的,巧妙。
如果之前存在过这个和,现在又出现了,说明这个区间1,0个数是相同的,相减为长度
我自己也手动模拟了一下,(相信你也看不懂= =,,,,属于自己能看懂序列。。。hh)