{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section 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\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eYou are given a string \u003cvar\u003e\\(S \u003d S_1 S_2 S_3 \\dots S_{|S|}\\)\u003c/var\u003e consisting of uppercase and lowercase English letters, \u003ccode\u003e(\u003c/code\u003e, and \u003ccode\u003e)\u003c/code\u003e.\u003cbr\u003e\r\nThe parentheses in the string \u003cvar\u003e\\(S\\)\u003c/var\u003e are properly matched.\u003c/p\u003e\r\n\u003cp\u003eRepeat the following operation until no more operations can be performed:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eFirst, select one pair of integers \u003cvar\u003e\\((l, r)\\)\u003c/var\u003e that satisfies all of the following conditions:\u003cul\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(l \u0026lt; r\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(S_l \u003d\\)\u003c/var\u003e \u003ccode\u003e(\u003c/code\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(S_r \u003d\\)\u003c/var\u003e \u003ccode\u003e)\u003c/code\u003e\u003c/li\u003e\r\n\u003cli\u003eEach of the characters \u003cvar\u003e\\(S_{l+1}, S_{l+2}, \\dots, S_{r-1}\\)\u003c/var\u003e is an uppercase or lowercase English letter.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/li\u003e\r\n\u003cli\u003eLet \u003cvar\u003e\\(T \u003d \\overline{S_{r-1} S_{r-2} \\dots S_{l+1}}\\)\u003c/var\u003e.\u003cul\u003e\r\n\u003cli\u003eHere, \u003cvar\u003e\\(\\overline{x}\\)\u003c/var\u003e denotes the string obtained by toggling the case of each character in \u003cvar\u003e\\(x\\)\u003c/var\u003e (uppercase to lowercase and vice versa).\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/li\u003e\r\n\u003cli\u003eThen, delete the \u003cvar\u003e\\(l\\)\u003c/var\u003e-th through \u003cvar\u003e\\(r\\)\u003c/var\u003e-th characters of \u003cvar\u003e\\(S\\)\u003c/var\u003e and insert \u003cvar\u003e\\(T\\)\u003c/var\u003e at the position where the deletion occurred.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eRefer to the sample inputs and outputs for clarification.\u003c/p\u003e\r\n\u003cp\u003eIt can be proved that it is possible to remove all \u003ccode\u003e(\u003c/code\u003es and \u003ccode\u003e)\u003c/code\u003es from the string using the above operations, and the final string is independent of how and in what order the operations are performed.\u003cbr\u003e\r\nDetermine the final string.\u003c/p\u003e\r\n\u003cdetails\u003e\r\n\u003csummary\u003eWhat does it mean that the parentheses in \u003cvar\u003e\\(S\\)\u003c/var\u003e are properly matched?\u003c/summary\u003e\r\nFirst, a correct parenthesis sequence is defined as follows:\r\n\r\n\u003cul\u003e\r\n\u003cli\u003eA correct parenthesis sequence is a string that satisfies one of the following conditions:\u003c/li\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eIt is an empty string.\u003c/li\u003e\r\n\u003cli\u003eThere exists a correct parenthesis sequence \u003cvar\u003e\\(A\\)\u003c/var\u003e, and the string is formed by concatenating \u003ccode\u003e(\u003c/code\u003e, \u003cvar\u003e\\(A\\)\u003c/var\u003e, \u003ccode\u003e)\u003c/code\u003e in this order.\u003c/li\u003e\r\n\u003cli\u003eThere exist non-empty correct parenthesis sequences \u003cvar\u003e\\(A\\)\u003c/var\u003e and \u003cvar\u003e\\(B\\)\u003c/var\u003e, and the string is formed by concatenating \u003cvar\u003e\\(A\\)\u003c/var\u003e and \u003cvar\u003e\\(B\\)\u003c/var\u003e in this order.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/ul\u003e\r\n\r\nThe parentheses in \u003cvar\u003e\\(S\\)\u003c/var\u003e are properly matched if and only if the \u003ccode\u003e(\u003c/code\u003es and \u003ccode\u003e)\u003c/code\u003es extracted from \u003cvar\u003e\\(S\\)\u003c/var\u003e without changing the order form a correct parenthesis sequence.\r\n\u003c/details\u003e\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\le |S| \\le 5 \\times 10^5\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(S\\)\u003c/var\u003e consists of uppercase and lowercase English letters, \u003ccode\u003e(\u003c/code\u003e, and \u003ccode\u003e)\u003c/code\u003e.\u003c/li\u003e\r\n\u003cli\u003eThe parentheses in \u003cvar\u003e\\(S\\)\u003c/var\u003e are properly matched.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Input","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eThe input is given from Standard Input in the following format:\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(S\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Output","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003ePrint the final string.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 1","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\u003e((A)y)x\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eYAx\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\u003cp\u003eLet us perform the operations for \u003cvar\u003e\\(S \u003d\\)\u003c/var\u003e \u003ccode\u003e((A)y)x\u003c/code\u003e.\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eChoose \u003cvar\u003e\\(l\u003d2\\)\u003c/var\u003e and \u003cvar\u003e\\(r\u003d4\\)\u003c/var\u003e. The substring \u003ccode\u003e(A)\u003c/code\u003e is removed and replaced with \u003ccode\u003ea\u003c/code\u003e.\u003cul\u003e\r\n\u003cli\u003eAfter this operation, \u003cvar\u003e\\(S \u003d\\)\u003c/var\u003e \u003ccode\u003e(ay)x\u003c/code\u003e.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/li\u003e\r\n\u003cli\u003eChoose \u003cvar\u003e\\(l\u003d1\\)\u003c/var\u003e and \u003cvar\u003e\\(r\u003d4\\)\u003c/var\u003e. The substring \u003ccode\u003e(ay)\u003c/code\u003e is removed and replaced with \u003ccode\u003eYA\u003c/code\u003e.\u003cul\u003e\r\n\u003cli\u003eAfter this operation, \u003cvar\u003e\\(S \u003d\\)\u003c/var\u003e \u003ccode\u003eYAx\u003c/code\u003e.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eAfter removing the parentheses, the string becomes \u003ccode\u003eYAx\u003c/code\u003e, which should be printed.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 2","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\u003e((XYZ)n(X(y)Z))\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eXYZNXYZ\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\u003cp\u003eLet us perform the operations for \u003cvar\u003e\\(S \u003d\\)\u003c/var\u003e \u003ccode\u003e((XYZ)n(X(y)Z))\u003c/code\u003e.\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eChoose \u003cvar\u003e\\(l\u003d10\\)\u003c/var\u003e and \u003cvar\u003e\\(r\u003d12\\)\u003c/var\u003e. The substring \u003ccode\u003e(y)\u003c/code\u003e is removed and replaced with \u003ccode\u003eY\u003c/code\u003e.\u003cul\u003e\r\n\u003cli\u003eAfter this operation, \u003cvar\u003e\\(S \u003d\\)\u003c/var\u003e \u003ccode\u003e((XYZ)n(XYZ))\u003c/code\u003e.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/li\u003e\r\n\u003cli\u003eChoose \u003cvar\u003e\\(l\u003d2\\)\u003c/var\u003e and \u003cvar\u003e\\(r\u003d6\\)\u003c/var\u003e. The substring \u003ccode\u003e(XYZ)\u003c/code\u003e is removed and replaced with \u003ccode\u003ezyx\u003c/code\u003e.\u003cul\u003e\r\n\u003cli\u003eAfter this operation, \u003cvar\u003e\\(S \u003d\\)\u003c/var\u003e \u003ccode\u003e(zyxn(XYZ))\u003c/code\u003e.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/li\u003e\r\n\u003cli\u003eChoose \u003cvar\u003e\\(l\u003d6\\)\u003c/var\u003e and \u003cvar\u003e\\(r\u003d10\\)\u003c/var\u003e. The substring \u003ccode\u003e(XYZ)\u003c/code\u003e is removed and replaced with \u003ccode\u003ezyx\u003c/code\u003e.\u003cul\u003e\r\n\u003cli\u003eAfter this operation, \u003cvar\u003e\\(S \u003d\\)\u003c/var\u003e \u003ccode\u003e(zyxnzyx)\u003c/code\u003e.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/li\u003e\r\n\u003cli\u003eChoose \u003cvar\u003e\\(l\u003d1\\)\u003c/var\u003e and \u003cvar\u003e\\(r\u003d9\\)\u003c/var\u003e. The substring \u003ccode\u003e(zyxnzyx)\u003c/code\u003e is removed and replaced with \u003ccode\u003eXYZNXYZ\u003c/code\u003e.\u003cul\u003e\r\n\u003cli\u003eAfter this operation, \u003cvar\u003e\\(S \u003d\\)\u003c/var\u003e \u003ccode\u003eXYZNXYZ\u003c/code\u003e.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eAfter removing the parentheses, the string becomes \u003ccode\u003eXYZNXYZ\u003c/code\u003e, which should be printed.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 3","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\u003e(((()))(()))(())\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\u003cp\u003eThe final outcome may be an empty string.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 4","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\u003edF(qT(plC())NnnfR(GsdccC))PO()KjsiI((ysA)eWW)ve\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003edFGsdccCrFNNnplCtQPOKjsiIwwEysAve\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\u003c/section\u003e\r\n"}}]}