{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"LYD有n个括号序列,并且他可以将这些串重新排列并把它们连接在一起得到一个新字符串t。现设f(t)为t中最长的平衡子序列的长度,他想知道在所有可能的t中,f(t)的最大值。\n\nHint:\n1. 子序列可以不连续; \n2. 平衡的括号序列有经典的递归定义如下:(1)空串是平衡的;(2)若串A和串B均平衡,则串AB平衡;(3)如果串A平衡,则串(A)平衡。"}},{"title":"Input","value":{"format":"MD","content":"多组数据,第一行一个整数T表示数据组数。\n每组数据第一行包含一个整数n(1\u003c\u003dn\u003c\u003d1e5)。\n以下n行每行一个仅由\u0027(\u0027或\u0027)\u0027组成的字符串si,1\u003c\u003d|si|\u003c\u003d1e5,且所有|si|之和不超过5e6。\n"}},{"title":"Output","value":{"format":"MD","content":"对每组数据,输出一个整数作为答案。"}},{"title":"Sample Input","value":{"format":"MD","content":"\u003cpre\u003e1\n2\n)\n)(\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"MD","content":"\u003cpre\u003e\n2\u003c/pre\u003e"}}]}