#include #include using namespace std; int main(){ string s;cin>>s; stack x; for(int i = 0; s.size() > i; i++){ //cout << s[i] << s[i+1] << endl; if('0' <= s[i] && s[i] <= '9'){ x.push(s[i]-'0'); }else if(i+1 != s.size() && s[i+1] == '('){ stack y; char l = s[i]; i+=2; while(s[i] != ')'){ if('0' <= s[i] && s[i] <= '9'){ y.push(s[i]-'0'); i++; }else if(s[i] == '+'){ int z = y.top();y.pop(); y.push(z+s[i+1]-'0'); i+=2; }else{ int z = y.top();y.pop(); y.push(z-(s[i+1]-'0')); i+=2; } } int b = x.top();x.pop(); if(l == '+'){ x.push(b+y.top()); }else{ x.push(b-y.top()); } }else{ int b = x.top();x.pop(); if(s[i] == '+'){ x.push(b+s[i+1]-'0'); i++; }else{ x.push(b-(s[i+1]-'0')); i++; } } //cout << x.top() << endl; } cout << x.top() << endl; }