| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10512 | Mid1_Exam Moving books |
|
| 10513 | Mid1_Exam Josephus composite |
|
| 10514 | Mid1_Exam Queue |
|
Description
The problem is to parse a series of commands to move the books that lie on the table. Initially there are n books lying on the table with book bi adjacent to book bi+1 for all , as shown in the diagram below:

Illegal commands:
- A = B
- A or B is not in the range (e.g. You cannot move or remove any book that does not exist)
Valid commands:
- move A on B
- move A under B
- remove A
- exit
Input
The input begins with an integer n on a line by itself representing the number of books in the book world. You may assume that 0 < n <= 10000.
The number of books is followed by a sequence of book commands, one command per line. Your program should process all commands until the exit command is encountered.
Output
Your output should contains one line of sequence which represents the order of books from the bottom to the top.
Each number is followed by a single space. And you are asked to add a new line character at the end
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Then print 6 as answer.
Input
Output
The output will consist in separate lines containing the position of the person which life will be saved.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Input
The string in the last line is always "END" indicating the end of the input.
Output
The output contains one line. The first string is the ID of the last group in the queue. After that you need to print the name of members in the last group, one by one according to their coming order.