#include #include #include using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) int main(){ string s; cin>> s; int n=s.size(); bool inside=false; // かっこの中か int res=0; for(int i=n-1; i>=0; i--){ if(s[i]==')'){ inside=true; }else if(s[i]=='('){ int j=i+1, sub=s[j++]-'0'; // ( 3 ... while(s[j]!=')'){ if(s[j]=='+') sub+=s[j+1]-'0'; // (3 + 4 ... else if(s[j]=='-') sub-=s[j+1]-'0'; // (3 - 4 ... j++; } int sgn=(i-1>=0 and s[i-1]=='-') ? -1 : 1; // ... - (3 + 4 - ...) res+=sub*sgn; inside=false; }else if('0'<=s[i] and s[i]<='9'){ if(inside) continue; int sub=s[i]-'0', sgn=(i-1>=0 and s[i-1]=='-') ? -1 : 1; // ... - 3 ... res+=sub*sgn; } } cout<< res<< endl; return 0; }