class MyStack {
private Queue<Integer> stack, queue;
public MyStack() {
this.stack = new LinkedList<>();
this.queue = new LinkedList<>();
}
public void push(int x) {
if (this.stack.size() == 0) this.stack.offer(x);
else {
this.queue.offer(x);
while (this.stack.size() != 0) this.queue.offer(this.stack.poll());
Queue<Integer> temp = this.stack;
this.stack = this.queue;
this.queue = temp;
}
}
public int pop() {
return this.stack.poll();
}
public int top() {
return this.stack.peek();
}
public boolean empty() {
return this.stack.size() == 0;
}
}