记录
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 1e9
#define pop pop()
#define top top()
#define empty empty()
#define size size()
string s[2100], s1;
stack<int>a;
int x[2100], m, n, q, qwe;
bool qwq;
void NUM(int w) {
if (abs(w) > N) {
qwq = 1;
return ;
}
a.push(w);
}
void INV() {
qwq = a.empty;
if (qwq == 1) return ;
int m = a.top;
a.pop;
NUM(0 - m);
}
void POP() {
qwq = a.empty;
if (qwq == 1) {
return ;
}
a.pop;
}
void DUP() {
qwq = a.empty;
if (qwq == 1) return;
NUM(a.top);
}
void SWP() {
qwq = (a.size) < 2;
if (qwq == 1) return ;
int x = a.top;
a.pop;
int y = a.top;
a.pop;
a.push(x);
a.push(y);
}
void ADD() {
qwq = a.size < 2;
if (qwq == 1) return ;
int x = a.top;
a.pop;
x += a.top;
a.pop;
NUM(x);
}
void SUB() {
qwq = (a.size < 2);
if (qwq == 1) return ;
int x = a.top;
a.pop;
int y = a.top;
a.pop;
NUM(x - y);
}
void MUL() {
qwq = (a.size < 2);
if (qwq == 1) return ;
int x = a.top;
a.pop;
int y = a.top;
a.pop;
NUM(x * y);
}
void MOD() {
qwq = (a.size < 2);
if (qwq == 1) return ;
int x = a.top;
a.pop;
int y = a.top;
a.pop;
if (x == 0) {
qwq = 1;
return ;
}
NUM(y % x);
}
void DIV() {
qwq = (a.size < 2);
if (qwq == 1) return ;
int x = a.top;
a.pop;
int y = a.top;
a.pop;
if (x == 0) {
qwq = 1;
return ;
}
NUM(y / x);
}
signed main() {
for (; ; qwe++) {
cin >> s[qwe];
if (s[qwe] == "NUM") {
cin >> x[m];
m++;
}
if (s[qwe] == "END") break;
}
cin >> n;
qwe--;
while (n--) {
cin >> q;
for (int i = 0; i < a.size; i++) {
a.pop;
}
m = 0;
qwq = 0;
NUM(q);
for (int i = 0; i <= qwe; i++) {
s1 = s[i];
if (qwq) {
cout << "ERROR\n";
break;
}
if (s1 == "NUM") {
NUM(x[m]);
m++;
}
if (s1 == "POP")
POP();
if (s1 == "INV")
INV();
if (s1 == "DUP")
DUP();
if (s1 == "SWP")
SWP();
if (s1 == "ADD")
ADD();
if (s1 == "SUB")
SUB();
if (s1 == "MUL")
MUL();
if (s1 == "DIV")
DIV();
if (s1 == "MOD")
MOD();
if (qwq) {
cout << "ERROR\n";
break;
}
}
if (!qwq) {
if (a.size == 1)
cout << a.top << "\n";
else cout << "ERROR\n";
}
}
return 0;
}