Implement an integer stack and process $n$ commands: push x pushes $x$; pop removes and prints the top (or $-1$ if empty); top prints the top (or $-1$ if empty); size prints the number of elements; empty prints $1$ if empty else $0$.
Input
First line $n$ ($1 \le n \le 100000$); then $n$ command lines. At least one command produces output.
Output
Print the result of each output-producing command, one per line.
Example 1
Input
5 push 1 top pop pop empty
Output
1 1 -1 1
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.