Balanced Substring，可以用一个前缀和的思路来做，详见本文内容。

# 题目

B. Balanced Substring

# 限制

time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

# 描述

You are given a string $s$ consisting only of characters $0$ and $1$. A substring $[l,r]$ of $s$ is a string $s_l$$s_{l+1}$$s_{l+2}$$…$$s_r$, 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$.

# 输入格式

The first line contains $n$ $(1 \le n \le 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$.

# 输出格式

If there is no non-empty balanced substring in $s$, print $0$. Otherwise, print the length of the longest balanced substring.

# 提示

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.

# 思路

mark数组中0到100000存储的是前缀和为-100000到0的首次出现位置。100001到200000存储的是前缀和为1到100000的首次出现位置。
mark数组首先初始化为-2，然后将mark设置为-1。每次计算前缀和，一旦发现某个mark对应某个前缀和在之前出现过，即不等于-2，那么就和res作比较。否则就更新mark的值为当前下标。