class MyQueue {
public:
stack<int> stIn;
stack<int> stOut;
MyQueue() {}
void push(int x) {
stIn.push(x);
}
int pop() {
if (stOut.empty()) {
while (!stIn.empty()) {
stOut.push(stIn.top());
stIn.pop();
}
}
int ans = stOut.top();
stOut.pop();
return ans;
}
int peek() {
int ans = this->pop();
stOut.push(ans);
return ans;
}
bool empty() {
return stOut.empty() && stIn.empty();
}
};
class MyStack {
public:
queue<int> que;
MyStack() {}
void push(int x) {
que.push(x);
}
int pop() {
int size = que.size() - 1;
while (size > 0) {
size--;
que.push(que.front());
que.pop();
}
int ans = que.front();
que.pop();
return ans;
}
int top() {
return que.back();
}
bool empty() {
return que.empty();
}
};