#include<iostream>
using namespace std;
const int N=1e5+10;
//hh默认为0,在还没有存入时tt不能大于hh
int q[N],hh,tt=-1,m;
int main()
{
cin>>m;
while(m--)
{
int x;
string op;
cin>>op;
if(op=="push")
{
cin>>x;
q[++tt]=x;
}
else if(op=="pop") hh++;
else if(op=="empty") cout<<( hh <= tt ? "NO" : "YES")<<endl;
else cout<<q[hh]<<endl;
}
return 0;
}