Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/stack-buyruqlari

Stack commands

Easy 1000 ms 128 MB 20%
Share

An empty stack and $n$ commands are given. In a stack the last element added comes out first: pop and top work with the most recently added element. Execute the commands in order.

  • push x — add the integer $x$ (nothing is printed);
  • pop — remove the element and print it;
  • top — print the element without removing it;
  • size — print the number of elements.

If the stack is empty, error is printed instead of pop and top (the stack does not change).

Stack cells one above another; arrows show that adding and removing happen on the same side

Input

The first line contains a positive integer $n$. Each of the next $n$ lines contains one command.

Output

For each of the pop, top and size commands, the answer on a separate line: an integer or error.

Note

$1 \le n \le 10^{5}$
$-10^{9} \le x \le 10^{9}$

Examples

Input #1
6
push 5
push 8
top
pop
top
size
Output #1
8
8
5
1
Input #2
3
pop
push 2
size
Output #2
error
1

Sign in to submit a solution

Signing up is free and takes a minute.