https://www.acmicpc.net/problem/10845
import java.util.*;
class Queue {
int first;
int last;
int[] queue;
public Queue(int num){
queue = new int[num];
first=0;
last=0;
}
public void push(int num) {
queue[last] = num;
last++;
}
public int pop() {
if(last-first == 0) return -1;
else {
int ans = queue[first];
queue[first] = 0;
first++;
return ans;
}
}
public int size() {
return last-first;
}
public int empty() {
if(last-first == 0) return 1;
else return 0;
}
public int front() {
if(last-first == 0) return -1;
else return queue[first];
}
public int back() {
if(last-first == 0) return -1;
else return queue[last - 1];
}
}
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int n=s.nextInt();
Queue t=new Queue(n);
for(int i=0;i<n;i++) {
String st = s.next();
switch (st) {
case "push":
t.push(s.nextInt());
break;
case "pop":
sb.append(t.pop()).append('\n');
break;
case "size":
sb.append(t.size()).append('\n');
break;
case "empty":
sb.append(t.empty()).append('\n');
break;
case "front":
sb.append(t.front()).append('\n');
break;
case "back":
sb.append(t.back()).append('\n');
break;
}
}
System.out.println(sb);
}
}