import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.<i>in</i>));
Queue<Character> Q = new LinkedList<>();
StringBuilder sb = new StringBuilder();
int N = Integer.<i>parseInt</i>(br.readLine());
char last = 0;
for (int i = 0; i < N; i++) {
String s = br.readLine();
if (s.startsWith("push")) {
Q.offer(s.charAt(5));
last = s.charAt(5);
} else if (s.equals("pop")) {
if (!Q.isEmpty()) sb.append(Q.poll()).append("\n");
else sb.append("-1\n");
} else if (s.equals("size")) {
sb.append(Q.size() + "\n");
} else if (s.equals("empty")) {
if (Q.isEmpty()) sb.append("1\n");
else sb.append("0\n");
} else if (s.equals("front")) {
if (Q.isEmpty()) sb.append("-1\n");
else sb.append(Q.peek() + "\n");
} else if (s.equals("back")) {
if (Q.isEmpty()) sb.append("-1\n");
else sb.append(last + "\n");
}
}
System.<i>out</i>.println(sb);
}
}
15
push 1
push 2
front
back
size
empty
pop
pop
pop
size
empty
pop
push 3
empty
front
1
2
2
0
1
2
-1
0
1
-1
0
3
nohriter 1년 전