class Stack {
queue<int> q;
int topval;
public:
// Push element x onto stack.
void push(int x) {
q.push(x);
topval = x;
}
// Removes the element on top of the stack.
void pop() {
int sz = q.size();
for (int i = 1; i < sz; ++i) {
topval = q.front();
q.pop();
q.push(topval);
}
q.pop();
}
// Get the top element.
int top() {
return topval;
}
// Return whether the stack is empty.
bool empty() {
return q.empty();
}
};