#include<iostream>
using namespace std;
int q[100005],t=-1;
int main()
{
int m,h,x;
scanf("%d",&m);
while(m--){
string op;
cin>>op;
if(op=="push"){
scanf("%d",&x);
t++,q[t]=x;
}
else if(op=="pop")h++;
else if(op=="empty")printf((h<=t?"NO\n":"YES\n"));
else printf("%d\n",q[h]);
}
return 0;
}