There are several NTHU students lining up for shu cream.
Each student belongs to a group identified by an integer g. When a student joins the queue:
g in the queue, this student will insert right behind the last student of group g.Occasionally, the staff scolds an entire group for being too loud. When this happens, all students of that group must move together to the end of the queue, while keeping their relative order unchanged.
Now, you are required to write a program to simulate the queue. There are four type of events:
JOIN id g: A student of student ID id and group g want to joint the queue.SCHOLD g: The staff scolds the students in group g.LEAVE: The first student in the queue gets his/her shu cream and leave the queue.ASK pos: Your program should answer what is the student ID of the student that is in the pos-th position of queue (1-base).Your program MAY use C++ standard library headers.
The first line contains a number N, representing the number of events.
For the next N lines, each line contains an event.
1 <= N <= 5 * 10^41 <= g <= 2000id <= 2 * 10^6pos is always less than or equal to the length of queue.g whenever the event SCOLD g happens.The student IDs, one per line. Each line should be newline ('\n') terminated.