#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define INF 1 << 29 #define LL long long int LL const MOD = 1000000007; LL priority(char x,char y){ if((x == '+' || x == '-') && y == '+'){ return 1; } if((x == '+' || x == '-') && y == '-'){ return 1; } if((x == '+' || x == '-') && y == '('){ return -1; } if((x == '+' || x == '-') && y == ')'){ return 1; } if((x == '+' || x == '-') && y == 'E'){ return 1; } if(x == '(' && y == ')'){ return 0; } if(x == '('){ return -1; } if(x == 'S' && x == 'E'){ return 0; } return -1; } int main(){ cin.tie(0); ios::sync_with_stdio(false); string str; cin >> str; str += 'E'; stack st; st.push('S'); int i = 0; string gyakupo = ""; bool endFrag = true; while(i < str.size() && endFrag){ int tmp = str[i] - '0'; if(tmp >= 0 && tmp <= 9){ gyakupo += str[i]; i++; }else{ int ret = priority(st.top(),str[i]); if(ret > 0){ gyakupo += st.top(); st.pop(); }else if(ret < 0){ st.push(str[i]); i++; }else{ if(st.top() == '('){ st.pop(); i++; }else{ endFrag = false; } } } } stack sim; for(int j = 0; j < gyakupo.size(); j++){ LL t = gyakupo[j] - '0'; if(t >= 0 && t <= 9){ sim.push(t); }else{ if(gyakupo[j] == '+'){ LL sec = sim.top();sim.pop(); LL fis = sim.top();sim.pop(); sim.push(fis+sec); }else{ LL sec = sim.top();sim.pop(); LL fis = sim.top();sim.pop(); sim.push(fis-sec); } } } cout << sim.top() << endl; return 0; }