11976 - Problem C   

Description

There are N numbers in a queue.  

The origin sequence is from 1 to N. (1 is the head).

The operation "Move a" means to move the first two numbers to the back of a without changing orderNote that if "a" is the first two numbers then you don't need to do anything. 

Given several such operations and output the final status of the sequence.

 

For example:

N = 5, then the sequence will be 1 2 3 4 5.  

If Move 3, the sequence will be 3 1 2 4 5. Since that the first two numbers is 1 2, you have to move 1 2 in the back of 3.

 

Input

There will be only one test case.

The test case begins with an integer N indicating the number of people.  

There are several operations followed.  The format is “Move a” (without quote).  

The test case is terminated by “Exit” (without quote).

 

subtask 1 : 1 <= N <= 100, you can use O(N) algo for each operation.

subtask 2 : 1 <= N <=100, you can use O(N) algo for each operation.

subtask 3 : 1 <= N <= 100000, you need use O(1) algo for each operation.

subtask 4 : 1 <= N <= 1000000, you need use O(1) algo for each operation.

Output

Output the numbers from the first one to the last one, and separate two consecutive numbers by a space.

You DON'T need to print "\n" or space at the end of the line.

Sample Input  Download

Sample Output  Download

Tags




Discuss