Question
Longest Balanced Binary Substring
You are given a binary string of length KaTeX can only parse string typed expression, consisting only of characters KaTeX can only parse string typed expression and KaTeX can only parse string typed expression. Your task is to find the maximum length of a substring that contains an equal number of KaTeX can only parse string typed expressions and KaTeX can only parse string typed expressions.
Input
The first line contains a single integer KaTeX can only parse string typed expression — the length of the string.
The second line contains a binary string KaTeX can only parse string typed expression of length KaTeX can only parse string typed expression, consisting only of characters KaTeX can only parse string typed expression and KaTeX can only parse string typed expression.
Output
Print a single integer — the maximum length of a substring that contains equal numbers of KaTeX can only parse string typed expressions and KaTeX can only parse string typed expressions.
Example
Input
7
1110001

Output
6

Explanation
The substring from index KaTeX can only parse string typed expression to KaTeX can only parse string typed expressionKaTeX can only parse string typed expression contains KaTeX can only parse string typed expression ones and KaTeX can only parse string typed expression zeros.

Online