MINSTACK  Smallest on the Stack
Every Christmas the good old man can go to every house in the world and leave gifts for the children who have been good throughout the year, but this is only possible because of his magic gift bag. It would be impossible for Santa to carry all the presents in his bag, the volume and weight of them all makes this obviously unfeasible. What actually happens is that your bag is a kind of magical portal to your gift factory at the North Pole. Where the presents are stacked by their elves and Noel always takes the gift from the top of that pile when he accesses his magical bag.
Gifts have a numerical measure of the degree of fun they can provide children, and Santa is always concerned with the least fun gift he will deliver throughout the night because he does not want any child to feel bad about it. you receive. However, this can not be done in advance because throughout the night as the good old man takes gifts from the pile to deliver, others are still being made and placed on the pile. So the most he can know is the value of the least fun present on the stack up to that point.
Your task is, given the sequence of operations done on the stack of gifts, answer Santa's queries about the value of the least entertaining gift on the stack thus far.
Input
The first line of the input contains an integer N (1 ≤ N ≤ 10^{6}) corresponding to the number of operations performed on the present stack. The operations can be of three types: "PUSH V" where V (1 ≤ V ≤ 10^{9}) is an integer representing the degree of fun of the present being placed on the stack; "POP" which represents that Santa Claus is taking a gift from the cell to deliver and "MIN" representing a Noel query to know the smallest gift value in the stack.
Output
The output consists of a line containing an integer with the smallest present value in the stack for queries of type "MIN" or "EMPTY" for "MIN" and "POP" operations when the stack is empty.
Example
Input: 11
PUSH 5
PUSH 7
PUSH 3
PUSH 8
PUSH 10
MIN
POP
POP
MIN
POP
MIN Output:3
3
5
Example
Input: 9
PUSH 100
PUSH 50
MIN
PUSH 45
MIN
POP
MIN
POP
MIN Output:50
45
50
100
hide comments
nadstratosfer:
20190319 08:36:55
Adarsh, this problem features large input so correct complexity might not be enough if the code style is poor, resulting in high constant factor, or IO method slow. Try various input methods at INTEST and see if you can get anywhere close to the Java top there: https://www.spoj.com/ranks/INTEST/lang=JAVA . This should help, albeit psetter is correct that it's absolutely possible to get AC without fast IO, or with a slow language. 

adarsh18213:
20190303 12:32:45
I'm new to SPOJ.


aadarsh45:
20190218 18:53:42
Be carefully about SIGSEGV Runtime error


ayushgupta1997:
20190211 20:19:56
Use ios_base::sync_with_stdio(false);cin.tie(0); for C++, atleast worked in my case :) 

zarif_2002:
20190205 05:59:57
no way, scanf and printf makes AC and cin and cout makes TLE.


Nishant Gupta:
20190110 13:36:52
@Robert : +1


y17prashant:
20190108 19:25:32
Simple stack implemenation . Just go for O(1) search of minimum element , to avoid TLE 

Francisco Elio Parente Arcos Filho [UEA]:
20181230 23:54:08
Its absolutely possible achieve the accepted without fast io 

Robert Gawron:
20181229 13:50:11
I had to replace cin by scanf to get acceptance due to too long processing time. 

julkas:
20181227 12:15:40
Happy New Year for all SPOJ users! 
Added by:  Francisco Elio Parente Arcos Filho [UEA] 
Date:  20181224 
Time limit:  1s1.200s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 