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

~/algor $ cat problems/stack-minimumli-stack

Min stack

Easy 1000 ms 128 MB 22%
Share

An empty stack and $n$ commands are given. Execute the commands in order.

  • push x — add the integer $x$ to the stack (nothing is printed);
  • pop — remove the most recently added element and print it;
  • min — print the smallest element of the stack (without removing it).

If the stack is empty, error is printed instead of pop and min.

Stack cells: next to each one, the smallest of the elements below it is stored

Input

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

Output

For each of the pop and min 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}$
at least one command prints an answer

Examples

Input #1
7
push 5
push 2
min
push 8
pop
pop
min
Output #1
2
8
2
5
Input #2
2
min
pop
Output #2
error
error

Sign in to submit a solution

Signing up is free and takes a minute.