AZY's Stack Test

时间限制: 1000 ms 内存限制: 65536 kb
总通过人数: 0 总提交人数: 0

Description

Basic operations of stack.

In computer science, a stack is an abstract data type(ADT) that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed. The order in which elements come off a stack gives rise to its alternative name, LIFO (for last in, first out).

Input

The input will consist of a set of operations and values.

For each set of input, first line will be a positive whole number, n, 0<n<=10000(n=0 means end of file).

Next n lines, each line will have a command operation, described by a string. ''USH", "OP" or "GET". "USH" will be followed by a int value, which should be pushed into the stack. For "OP", you should pop the top element out from the stack. And "GET" means you should return the top element(a value), if the stack is empty(so that we will not have any "top element"), return "EMPTY!".

Output

You should read the commands and operate on the stack, and print top element when you get string "GET". Do not forget to add an empty line after each set of operations finished.

Sample Input

1
GET
2
USH 3
GET
0

Sample output

EMPTY!

3

Warning

Codes using STL will not be admitted.

相关推荐