?
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] stl = new int[100010];//栈
int m = sc.nextInt();//输入次数
int tt = 0;//栈顶
while (m-- > 0){
String s = sc.next();
if (s.equals("push")){
int x = sc.nextInt();
stl[++tt] = x;
} else if (s.equals("pop")){
tt--;
} else if (s.equals("empty")){
if (tt > 0){
System.out.println("NO");
} else {
System.out.println("YES");
}
} else {
System.out.println(stl[tt]);
}
}
}
}