#include <bits/stdc++.h>
using namespace std;
stack<int> s;
int main()
{
int m;
cin >> m;
while (m -- )
{
string a;
cin >> a;
if (a == "push")
{
int b;
cin >> b;
s.push(b);
}
else if(a == "pop")
{
s.pop();
}
else if(a == "empty")
{
if (s.empty()) cout << "YES\n";
else cout << "NO\n";
}
else
{
cout << s.top() << endl;
}
}
}