{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n #problem-body \u003e pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv id\u003d\"problem-body\"\u003e\n\t\u003cp\u003eI’m out of stories. For years I’ve been writing stories, some rather silly, just to make simple problems look difficult and complex problems look easy. But, alas, not for this one.\u003c/p\u003e\r\n\u003cp\u003eYou’re given a non empty string made in its entirety from opening and closing braces. Your task is to find the minimum number of “operations” needed to make the string stable. The definition for being stable is as follows:\u003c/p\u003e\r\n\u003col\u003e\r\n\u003cli\u003eAn empty string is stable.\u003c/li\u003e\r\n\u003cli\u003eIf S is stable, then {S} is also stable.\u003c/li\u003e\r\n\u003cli\u003eIf S and T are both stable, then ST (the concatenation of the two) is also stable.\u003c/li\u003e\r\n\u003c/ol\u003e\r\n\u003cp\u003eAll of these strings are stable: {}, {}{}, and {{}{}}; But none of these: }{, {{}{, nor {}{. \u003cbr\u003eThe only operation allowed on the string is to replace an opening brace with a closing brace, or vice-versa.\u003c/p\u003e\r\n\u003ch3\u003eInput\u003c/h3\u003e\r\n\u003cp\u003eYour program will be tested on one or more data sets. Each data set is described on a single line. The line is a non-empty string of opening and closing braces and nothing else. No string has more than 2000 braces. All sequences are of even length.\u003c/p\u003e\r\n\u003cp\u003eThe last line of the input is made of one or more ’-’ (minus signs.)\u003c/p\u003e\r\n\u003ch3\u003eOutput\u003c/h3\u003e\r\n\u003cp\u003eFor each test case, print the following line:\u003c/p\u003e\r\n\u003cp\u003ek. N\u003c/p\u003e\r\n\u003cp\u003eWhere k is the test case number (starting at one,) and N is the minimum number of operations needed to convert the given string into a balanced one.\u003c/p\u003e\r\n\u003ch3\u003eExample\u003c/h3\u003e\r\n\u003cdiv\u003e\u003ctable class\u003d\"vjudge_sample\"\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\u003e}{\n{}{}{}\n{{{}\n---\n\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1. 2\n2. 0\n3. 1\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e"}}]}