MINSTOCK  Minimum Stocks
Himanshu wants to invest into stock market and his friend Navneet helps him by providing him instruction for next N days.
Navneet gives Himanshu 3 types of instruction,
1 X Y There is a stock X available at price Y. Here X is a string and Y is an integer.
2 X Z The price of stock X has changed to Z. Here X is a string and Z is an integer.
3 BUY Buy the stock which has the lowest price.
You as a programmer, is given all the instructions of N days. Can you tell, which stock did Himanshu buy on which day. Print the output in same order as himanshu bought the stock. See sample Input and Output for Clarification.
At any point of time, there is atmost one stock of X. However, X can be made available to market again through another instruction of type 1.
All instructions are valid. i.e There is always some stock to buy having the minimum price of all. Also if the price of X has changed, then X is already known and hasn't been bought yet.
INPUT
First line contains N. (1 ≤ N ≤ 10^{6})
Next N lines, each of them contains an instruction of any of 3 types. (Look at instruction format above)
In any instruction, (X is a string of length upto 10 characters. All characters are from english alphabets, both small and capital ) , and (0 ≤ Y ≤ 10^{9)} and (0 ≤ Z ≤ 10^{9)} .
OUTPUT
For each instruction of type 3, output two values X and Y. Where X is the name of Stock having minimum price and Y is the day on which it was bought.
Example
Input :7
1 ABC 32
1 XDC 54
3 BUY
1 XCD 32
1 ABC 12
2 XDC 10
3 BUY
Output :
ABC 3
XDC 7
Explanation
On day 3, there is instruction to buy. There are two stocks available "XDC" and "ABC", since price of "ABC" is less, he buys it. After this "ABC" is not available in market anymore.
On day 7, there is instruction to buy. Of all stocks available, "XDC" has the least price and hence he buys "XDC".
hide comments
vaishcr7:
20190716 11:06:04
Anyone getting WA. LOOK AT THIS.


y17prashant:
20190107 22:46:56
Used same mapping .....got TLE in java and AC in cpp...........Nice question


sanchit_aga:
20190107 10:51:05
got WA on test case 10...any suggestions?


Masha Zryanina:
20181210 21:37:37
I did not understand why the output for XCD is 7 in the example, not 10. There were no instructions in the provided input that set price of XCD to 7.


DOT:
20180924 19:38:56
Nice question. @Author, please mention the possible characters of the string X in the problem description.


Palashvijay4O:
20180921 11:23:28
My submission #22355284 is giving wrong answer on test case 9. My solution is in Java.


dhi13man:
20180920 11:19:00
My code is giving correct result in 2 other IDEs and it's still showing runtime error here :(

Added by:  Prakash Jha 
Date:  20180919 
Time limit:  0.5s1.200s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  Own Problem 