#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int stk[N];
int top = 0;
int main()
{
int m;
cin >> m;
while (m -- )
{
string op;
int x;
cin >> op;
if (op == "push") //进栈
{
cin >> x;
stk[top ++ ] = x;
}
else if (op == "pop") //出栈
{
top -- ; //不需要真的出栈,只要栈顶指针减1即可
}
else if (op == "empty") //判空
{
if (!top) printf("YES\n");
else printf("NO\n");
}
else //查询栈顶元素
{
printf("%d\n", stk[top - 1]);
}
}
return 0;
}