import java.util.Scanner;
import java.io.BufferedInputStream;
class Main {
static int[] save = new int[100010];
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
int len = sc.nextInt(), start = 0, end = -1;
sc.nextLine();
while (len-- > 0) {
String cmd = sc.nextLine();
switch (cmd.charAt(0)) {
case 'e'://Empty?
System.out.println(end < start ? "YES" : "NO");
break;
case 'q':
System.out.println(save[start]);
break;
case 'p':
if (cmd.charAt(1) == 'u')//PUSH
save[++end] = Integer.parseInt(cmd.substring(5, cmd.length()));
else//POP
start++;
break;
}
}
}
}