#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define llong long long int calc(char op, int ee, int er) { if(op == '+') return ee + er; return ee - er; } int main() { string s; cin >> s; int ee = 0; int er = 0; char op = '+'; char opbr = '+'; bool inbracket = false; for(char c: s) { switch(c) { case '+': case '-': if(inbracket) opbr = c; else op = c; break; case '(': inbracket = true; break; case ')': inbracket = false; ee = calc(op, ee, er); er = 0; opbr = '+'; break; default: if(inbracket) er = calc(opbr, er, stoi(""s + c)); else ee = calc(op, ee, stoi(""s + c)); break; } } cout << ee << "\n"; }