P9518 queue
Background
You are right, but MaiMai DX is a game and then I forgot the rest.
Description
**Additional note: The “queueing” here is different from the usual one. The people who are currently playing are considered the first two positions of the queue, so playing is treated as queueing.**
There is an arcade with one game machine, and at most two people can play at the same time. But clearly, more than two people may come to play! So they need to line up. You need to write a program to maintain this queue, and notify the next players after others finish playing. During the whole process, the following events may happen:
- `start`: A round of the game starts. If this is not the first round, then the participants of the previous round return to the back of the queue in their original order **at the instant right before** this round starts. Now you should output the names of the people who will play this round in the order in the queue (normally the first two people in the queue, or the only one). If there are two, separate them with a space. If nobody plays in this round, output `Error` and ignore this event.
- `arrive x`: $x$ arrives at the arcade and joins the back of the queue. At this time, $x$ should not already be in the queue; otherwise output `Error` and ignore this event. If the event is executed successfully, output `OK`.
- `leave x`: $x$ leaves the arcade and leaves the queue. At this time, $x$ should be in the queue but should not be playing; otherwise output `Error` and ignore this event. If the event is executed successfully, output `OK`.
You need to maintain the queue information and output what is required for the events above.
Input Format
The first line contains an integer $n$, the number of events.
The next $n$ lines each describe one event.
Output Format
Output $n$ lines as required by the statement, representing the program’s response to each event.
Explanation/Hint
**Sample Explanation**
In sample $1$, the following events happen:
- At the first `start`, the queue is empty, so output `Error`.
- `A` then joins the queue.
- At the second `start`, there is only `A`, so output `A`.
- `B, C, D` then join the queue in order.
- At the third `start`, `B, C` play.
- `C` tries to leave, but he is playing, so output `Error`.
- `D` leaves successfully.
- At the fourth `start`, `A, B` play.
- `A` tries to join the queue, but he is already in the queue, so output `Error`.
- `D` joins the queue again.
- `E` tries to leave, but is not in the queue at all, so output `Error`.
- At the fifth `start`, `C, D` play.
In sample $2$, `A, B, C` join the queue in order. All operations are legal, so output three `OK`.
**Constraints**
For $20\%$ of the testdata, it is guaranteed that $n=1$.
For $40\%$ of the testdata, it is guaranteed that $n \le 2000$.
For another $20\%$ of the testdata, it is guaranteed that there is no `leave` operation.
For another $20\%$ of the testdata, names can only be a single uppercase letter.
For $100\%$ of the testdata, it is guaranteed that $1 \le n \le 10^5$, and each name contains only uppercase and lowercase letters and has length at most $10$.
**The input and output size of this problem is large, so please use efficient I/O methods.**
Translated by ChatGPT 5