Category

Similar Problems

0733. Minimum in the Stack

Time limit : 2000 ms
Memory limit : 64 mb

The input to a program is a set of operations with a stack. Each operation is either an addition or removal of an item to or from the stack. After each operation find the smallest number in a stack. Summarize all the resulting numbers and get the answer. If after any operation the stack is empty, then add nothing to the answer. If it is impossible to remove an item because the stack is empty, then do nothing.

    Input

In the first line given a number m – the numbers of operations(1≤n≤105). Next n lines contain the type operation. It may push or pop. If it is push then given a number wich adding to stack. The numbers are in range from 1 to 109.

   Output

   Print one number - the result.

   Samples

Input

Output

1

9

push 5

push 3

pop

pop

pop

push 10

push 11

push 1

pop

44

2

1

pop

0

 

Tayyorladi: Azat Yusupov
Text from: e-olimp.com