#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int m;
int q[N];
int hh,tt;
int main()
{
cin >> m;
while (m -- )
{
string op;
cin >> op;
int x;
if(op == "push")
{
cin >> x;
q[tt ++ ] = x;
}
else if(op == "pop")
{
hh ++ ;
}
else if(op == "empty")
{
if(hh == tt)
puts("YES");
else
puts("NO");
}
else
{
cout << q[hh] << endl;
}
}
return 0;
}