13244 - AI Vendor   

Description

DuckDuck are a lazy vendor. To keep up with the trend of AI, he wants to write a program to handle the stall automatically. Can you help him?
The commodity (商品) has weight and price. Initially there're some commodities (the left over from yesterday). The program has to handle four types of event.

1. Add a new commodity with specific weight and price to your stall.
2. Customer ask for one commodity with specific weight and price. If there exsist such commodity, sell him/her.
3. Customer ask for one commodity with weight at least w. If there exsist such commodity, sell him/her the lightest one in all the commodity that weight is at least w, if there're still multiple choices, sell him/her the cheapest one.
4. Customer ask for one commodity with price at most v. If there exsist such commodity, sell him/her the most expensive one in all the commodity that price is at most v, if there're still multiple choices, sell him/her the lightest one.

Input

The first line contains a single integer N (N <= 100000) representing the number of commodity you initially own. The next N lines each contain two integers representing the weight and price weight and price of each commodity.
Next line contains a single integer Q (Q <= 100000) representing the number of events. The next Q lines representing the information of each events.
For each events, first contains an integer representing the type of the event.
If the type is 1 or 2, then there will be two integers follow, representing the weight and price respectively.
If the type is 3 or 4, then there will be one integer follows, representing the weight or price depending on the type of events).
Guarantee that (1 <= all the weight and price <= 1000000)

Constraint of testcases:

Testcase 1 ~ 2: N, Q <= 2000, event type = {1, 2, 3}, commodity in your stall are all unique.
Testcase 2 ~ 4: Event type = {1, 2, 3}, commodity in your stall are all unique.
Testcaes 5: Commodity in your stall are all unique.
Testcaes 6: Event type = {1, 2, 3}
Testcaes 7 ~ 8: No other constraint.

 

Output

For event type 2, if you sell the customer output "OK", otherwise output "No Item".
For event type 3 and 4, if you sell the customer please output "OK" and the weight and price of the commodity that you sell seperated by space, otherwise output "No Item"
Remember to add a newline character at the end of the output of each event.
 

Sample Input  Download

Sample Output  Download

Tags




Discuss