#include using namespace std; const int N = 100010; int stk[N], tt; int main() { string op; int n; cin >> n; while (n--) { cin >> op; if (op == "push") { int x; cin >> x; stk[++tt] = x; } else if (op == "pop") tt--; else if (op == "query") printf("%d\n", stk[tt]); else if (op == "empty") { if (tt == 0) printf("YES\n"); else printf("NO\n"); } } return 0; }