{"trustable":true,"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":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eChiaki有$n$个字符串$s_1,s_2,\\dots,s_n$,每个字符串由\u0027(\u0027和\u0027)\u0027组成。这种类型的字符串被称为平衡的:\u003cbr\u003e\u003cbr\u003e+ 如果它是空字符串\u003cbr\u003e+ 如果$A$和$B$是平衡的,则$AB$也是平衡的\u003cbr\u003e+ 如果$A$是平衡的,则$(A)$也是平衡的。\u003cbr\u003e\u003cbr\u003eChiaki可以重新排列这些字符串,然后将它们连接起来得到一个新的字符串$t$。设$f(t)$为$t$的最长平衡子序列(不一定连续)的长度。Chiaki想要知道所有可能的$t$的最大值$f(t)$。\u003cbr\u003e\u003c/div\u003e"}},{"title":"输入","value":{"format":"HTML","content":"有多个测试用例。输入的第一行包含一个整数$T$,表示测试用例的数量。对于每个测试用例:\u003cbr\u003e第一行包含一个整数$n$($1 \\le n \\le 10^5$)-- 字符串的数量。\u003cbr\u003e接下来的$n$行中,每行包含一个由`(\u0027和`)`组成的字符串$s_i$($1 \\le |s_i| \\le 10^5$)。\u003cbr\u003e保证所有$|s_i|$的总和不超过$5 \\times 10^6$。\u003cbr\u003e"}},{"title":"输出","value":{"format":"HTML","content":"对于每个测试用例,输出一个整数表示答案。\u003cbr\u003e"}},{"title":"示例","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n1\r\n)()(()(\r\n2\r\n)\r\n)(\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4\r\n2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}}]}