{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eThe new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of the bank is identified by a positive integer \u003ci\u003eK\u003c/i\u003e and, upon arriving to the bank for some services, he or she receives a positive integer priority \u003ci\u003eP\u003c/i\u003e. One of the inventions of the young managers of the bank shocked the software engineer of the serving system. They proposed to break the tradition by sometimes calling the serving desk with the \u003cb\u003elowest\u003c/b\u003e priority instead of that with the highest priority. Thus, the system will receive the following types of request:\u003c/p\u003e\u003ctable style\u003d\"border-collapse: collapse;\" border\u003d\"1\" bordercolor\u003d\"#000000\"\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e0\u003c/td\u003e\u003ctd\u003eThe system needs to stop serving\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e1 \u003ci\u003eK\u003c/i\u003e \u003ci\u003eP\u003c/i\u003e\u003c/td\u003e\u003ctd\u003eAdd client \u003ci\u003eK\u003c/i\u003e to the waiting list with priority \u003ci\u003eP\u003c/i\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e2\u003c/td\u003e\u003ctd\u003eServe the client with the highest priority and drop him or her from the waiting list\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e3\u003c/td\u003e\u003ctd\u003eServe the client with the lowest priority and drop him or her from the waiting list\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\u003cp\u003eYour task is to help the software engineer of the bank by writing a program to implement the requested serving policy.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eEach line of the input contains one of the possible requests; only the last line contains the stop-request (code 0). You may assume that when there is a request to include a new client in the list (code 1), there is no other request in the list of the same client or with the same priority. An identifier \u003ci\u003eK\u003c/i\u003e is always less than 10\u003csup\u003e6\u003c/sup\u003e, and a priority \u003ci\u003eP\u003c/i\u003e is less than 10\u003csup\u003e7\u003c/sup\u003e. The client may arrive for being served multiple times, and each time may obtain a different priority.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each request with code 2 or 3, the program has to print, in a separate line of the standard output, the identifier of the served client. If the request arrives when the waiting list is empty, then the program prints zero (0) to the output.\u003c/p\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n1 20 14\r\n1 30 3\r\n2\r\n1 10 99\r\n3\r\n2\r\n2\r\n0\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\r\n20\r\n30\r\n10\r\n0\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}