#include <iostream> #include <string> #include <stack> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string input; cin >> input; int par = 0; for (int i = 0; i < input.size(); i++) { if (input[i] == '(') par++; else if (input[i] == ')') par--; else if(par>0 && (par & 1)) if (islower(input[i])) input[i] = toupper(input[i]); else input[i] = tolower(input[i]); } stack<string> ts; ts.push(""); for (int i = 0; i < input.size(); i++) { if (input[i] == '(') { ts.push(""); } else if (input[i] == ')') { reverse(ts.top().begin(),ts.top().end()); string reversed = ts.top(); ts.pop(); string& topElement = ts.top(); topElement.append(reversed); } else { string& topElement = ts.top(); topElement.push_back(input[i]); } } cout << ts.top(); }