{"raw_statement":[{"iden":"statement","content":"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.\n\nYou have to determine the length of the longest _balanced_ substring of _s_."},{"iden":"input","content":"The first line contains _n_ (1 ≤ _n_ ≤ 100000) — the number of characters in _s_.\n\nThe second line contains a string _s_ consisting of exactly _n_ characters. Only characters _0_ and _1_ can appear in _s_."},{"iden":"output","content":"If there is no non-empty _balanced_ substring in _s_, print _0_. Otherwise, print the length of the longest _balanced_ substring."},{"iden":"examples","content":"Input\n\n8\n11010111\n\nOutput\n\n4\n\nInput\n\n3\n111\n\nOutput\n\n0"},{"iden":"note","content":"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.\n\nIn the second example it's impossible to find a non-empty _balanced_ substring."}],"translated_statement":[{"iden":"statement","content":"给定一个仅由字符 _0_ 和 _1_ 组成的字符串 #cf_span[s]。字符串 #cf_span[s] 的子串 #cf_span[[l, r]] 是指字符串 #cf_span[slsl + 1sl + 2... sr]，其长度为 #cf_span[r - l + 1]。如果一个子串中零 (_0_) 的数量等于一的数量，则称该子串为 _平衡的_。\n\n你需要确定 #cf_span[s] 的最长 _平衡_ 子串的长度。\n\n第一行包含 #cf_span[n] (#cf_span[1 ≤ n ≤ 100000]) —— #cf_span[s] 中字符的个数。\n\n第二行包含一个恰好由 #cf_span[n] 个字符组成的字符串 #cf_span[s]。#cf_span[s] 中仅可能出现字符 _0_ 和 _1_。\n\n如果 #cf_span[s] 中不存在非空的 _平衡_ 子串，则输出 _0_。否则，输出最长 _平衡_ 子串的长度。\n\n在第一个例子中，你可以选择子串 #cf_span[[3, 6]]。它是 _平衡的_，长度为 #cf_span[4]。选择子串 #cf_span[[2, 5]] 也是可行的。\n\n在第二个例子中，无法找到任何非空的 _平衡_ 子串。\n\n"},{"iden":"input","content":"第一行包含 #cf_span[n] (#cf_span[1 ≤ n ≤ 100000]) —— #cf_span[s] 中字符的个数。第二行包含一个恰好由 #cf_span[n] 个字符组成的字符串 #cf_span[s]。#cf_span[s] 中仅可能出现字符 _0_ 和 _1_。"},{"iden":"output","content":"如果 #cf_span[s] 中不存在非空的 _平衡_ 子串，则输出 _0_。否则，输出最长 _平衡_ 子串的长度。"},{"iden":"examples","content":"输入811010111输出4输入3111输出0"},{"iden":"note","content":"在第一个例子中，你可以选择子串 #cf_span[[3, 6]]。它是 _平衡的_，长度为 #cf_span[4]。选择子串 #cf_span[[2, 5]] 也是可行的。在第二个例子中，无法找到任何非空的 _平衡_ 子串。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the length of the string.  \nLet $ s = s_1 s_2 \\dots s_n $ be a string over $ \\{0, 1\\} $.  \nFor a substring $ s[l:r] = s_l s_{l+1} \\dots s_r $, define its balance as:  \n$$\n\\text{balance}(l, r) = (\\text{count of } 1\\text{s in } s[l:r]) - (\\text{count of } 0\\text{s in } s[l:r])\n$$  \nA substring $ s[l:r] $ is *balanced* if $ \\text{balance}(l, r) = 0 $.\n\n**Constraints**  \n1. $ 1 \\leq n \\leq 100000 $  \n2. $ s_i \\in \\{0, 1\\} $ for all $ i \\in \\{1, \\dots, n\\} $\n\n**Objective**  \nFind the maximum length $ r - l + 1 $ over all substrings $ s[l:r] $ such that $ \\text{balance}(l, r) = 0 $.  \nIf no such non-empty substring exists, output $ 0 $.","simple_statement":null,"has_page_source":false}