{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\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 type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eYou are given a string $$$s$$$, consisting of brackets of two types: \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e(\u003c/span\u003e\u0027, \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e)\u003c/span\u003e\u0027, \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e[\u003c/span\u003e\u0027 and \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e]\u003c/span\u003e\u0027.\u003c/p\u003e\u003cp\u003eA string is called a regular bracket sequence (RBS) if it\u0027s of one of the following types: \u003c/p\u003e\u003cul\u003e \u003cli\u003e empty string; \u003c/li\u003e\u003cli\u003e \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e(\u003c/span\u003e\u0027 + RBS + \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e)\u003c/span\u003e\u0027; \u003c/li\u003e\u003cli\u003e \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e[\u003c/span\u003e\u0027 + RBS + \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e]\u003c/span\u003e\u0027; \u003c/li\u003e\u003cli\u003e RBS + RBS. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003ewhere plus is a concatenation of two strings.\u003c/p\u003e\u003cp\u003eIn one move you can choose a non-empty subsequence of the string $$$s$$$ (not necessarily consecutive) that is an RBS, remove it from the string and concatenate the remaining parts without changing the order.\u003c/p\u003e\u003cp\u003eWhat is the maximum number of moves you can perform?\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$)\u0026nbsp;— the number of testcases.\u003c/p\u003e\u003cp\u003eEach of the next $$$t$$$ lines contains a non-empty string, consisting only of characters \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e(\u003c/span\u003e\u0027, \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e)\u003c/span\u003e\u0027, \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e[\u003c/span\u003e\u0027 and \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e]\u003c/span\u003e\u0027. The total length of the strings over all testcases doesn\u0027t exceed $$$2 \\cdot 10^5$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each testcase print a single integer\u0026nbsp;— the maximum number of moves you can perform on a given string $$$s$$$.\u003c/p\u003e"}},{"title":"Examples","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\u003e5\n()\n[]()\n([)]\n)]([\n)[(]\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\n2\n2\n0\n1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first example you can just erase the whole string.\u003c/p\u003e\u003cp\u003eIn the second example you can first erase the brackets on positions $$$1$$$ and $$$2$$$: \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003e[]\u003c/span\u003e()\u003c/span\u003e\", then \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e()\u003c/span\u003e\" is left. After that you can erase it whole. You could erase the whole string from the beginning but you would get one move instead of two.\u003c/p\u003e\u003cp\u003eIn the third example you can first erase the brackets on positions $$$1$$$ and $$$3$$$: \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e\u003cspan class\u003d\"tex-font-style-bf\"\u003e(\u003c/span\u003e[\u003cspan class\u003d\"tex-font-style-bf\"\u003e)\u003c/span\u003e]\u003c/span\u003e\". They form an RBS \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e()\u003c/span\u003e\". Then \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e[]\u003c/span\u003e\" is left, so you can erase it whole.\u003c/p\u003e\u003cp\u003eIn the fourth example there is no subsequence that is an RBS, so you can\u0027t perform a move at all.\u003c/p\u003e\u003cp\u003eIn the fifth example you can erase the brackets on positions $$$2$$$ and $$$4$$$: \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e)\u003cspan class\u003d\"tex-font-style-bf\"\u003e[\u003c/span\u003e(\u003cspan class\u003d\"tex-font-style-bf\"\u003e]\u003c/span\u003e\u003c/span\u003e\" and get \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e)(\u003c/span\u003e\" as a result. You can erase nothing from it.\u003c/p\u003e"}}]}