#include #include #include #include #include #include #include #include #include #include using namespace std; #define DEBUG 0 #define III if(DEBUG >1) #define VVV if(DEBUG) typedef long long ll; ll param; list st; bool NUM() { st.push_back(param); return 1; } bool POP() { if ( ! st.size()) return 0; st.pop_back(); return 1; } bool INV() { if ( ! st.size()) return 0; ll a = - st.back(); st.pop_back(); st.push_back(a); return 1; } bool DUP(){ if ( ! st.size()) return 0; st.push_back( st.back() ); return 1; } bool SWP(){ if ( st.size() <2) return 0; ll a,b; a=st.back(); st.pop_back(); b=st.back(); st.pop_back(); st.push_back(a); st.push_back(b); return 1; } bool ADD() { if ( st.size() <2) return 0; ll c= st.back(), tmp =c; st.pop_back(); c += st.back(); st.pop_back(); if (abs(c) >1e9) return 0; st.push_back(c); return 1; } bool SUB() { if ( st.size() <2) return 0; ll c, tmp =st.back(); st.pop_back(); c = st.back() -tmp; st.pop_back(); if (abs(c) >1e9) return 0; st.push_back(c); return 1; } bool MUL() { if ( st.size() <2) return 0; ll c, tmp =st.back(); st.pop_back(); c = st.back()*tmp; st.pop_back(); if (abs(c) >1e9) return 0; st.push_back(c); return 1; } bool DIV(){ if ( st.size() <2) return 0; ll c, d, tmp =st.back(); if (! tmp) return 0; st.pop_back(); d =st.back(); c = abs(st.back()) / abs(tmp); st.pop_back(); if (abs(c) >1e9) return 0; //sign workaround if ((d<0)==(tmp<0)) ; else c=-c; st.push_back(c); return 1; } bool MOD(){ if ( st.size() <2) return 0; ll c, d, tmp =st.back(); if (! tmp) return 0; st.pop_back(); d =st.back(); c = abs(st.back()) % abs(tmp); st.pop_back(); if (abs(c) >1e9) return 0; //sign workaround if ((d<0)) c=-c; st.push_back(c); return 1; } map a; bool (*func[])()={NUM, POP, INV, DUP, SWP,ADD,SUB,MUL,DIV,MOD}; int inst[210000]; int main() { III cout <<"ahoj\n"; string ln; III cout <<"ahoj\n"; while (1) { III cout <<"ahoj\n"; cin >> ln; int ind =0; ///program read if (ln=="QUIT") return 0; while(ln[0] !='E') { switch (ln[0]) { case 'N': inst[ind]=0; ind++; cin >> inst[ind]; ind++; break; case 'P': inst[ind]=1; ind++; break; case 'I': inst[ind]=2; ind++; break; case 'D': if (ln[1]=='U') { inst[ind]=3; ind++; break; } if (ln[1]=='I') { inst[ind]=8; ind++; break; } III cout <<"PROBLEM\n"; break; case 'S': if (ln[1]=='W') { inst[ind]=4; ind++; break; } if (ln[1]=='U') { inst[ind]=6; ind++; break; } III cout <<"PROBLEM\n"; break; case 'A': inst[ind]=5; ind++; break; case 'M': if (ln[1]=='U') { inst[ind]=7; ind++; break; } if (ln[1]=='O') { inst[ind]=9; ind++; break; } III cout <<"PROBLEM\n"; break; } cin >> ln; } ///stack read III cout <<"ahoj\n"; ll n, k; cin >>n; bool error=0; for(; n>0; n--) { //readup 1 stack! error =0; st.clear(); cin >> k; st.push_back( k); ///work for(int j=0; j