Stack with Array
Implement a stack data structure using an array. Read a sequence of commands and process them:
- push X: push integer X onto the stack
- pop: remove and print the top element, or print
Emptyif the stack is empty - peek: print the top element without removing it, or print
Emptyif the stack is empty
Input
- First line: an integer
M(1 <= M <= 2·10^4), the number of commands - For each command:
- Line 1: command type (
push,pop, orpeek) - Only for
push, line 2: the integer X (-10^9 <= X <= 10^9)
- Line 1: command type (
Output
For each pop or peek command, print one line: the value or Empty.
Examples
Input:
5
push
10
push
20
peek
pop
pop
Output:
20
20
10
Input:
3
pop
push
5
peek
Output:
Empty
5
Input:
5
push
1
push
2
pop
pop
pop
Output:
2
1
Empty
Once the stack is fully drained, further pop calls keep printing Empty.