13421 - Camo the Train Conductor   

Description

Camo is a train conductor, she wants to adjust the train he's driving.

 

There are six instructions below with the description:

 

You don't need to implement red instructions which are done by Domo!

 

1. AddFront num

Add a train carriage with the index num in front of the train.

 

2. AddBack num

Add a train carriage with the index num in back of the train.

 

3. Delete num

Delete all the train carriages with the index num from the train. (If the train has no any carriage with the index num, do nothing)

 

4. DeleteFront

Delete the first element of the train. (If the train is empty, do nothing)

 

5. DeleteRange num1 num2

Delete carriages between the num1-th carriage and the num2-th carriage (Start counting from 1, if the given range is out of the bound, do nothing.)

 

6. Swap

Reverse all train carriages. (If the train is empty, do nothing)

 

For example:

AddFront 5 makes the train [4, 1] become [5, 4, 1].

AddBack 5 makes the train [4, 1] become [4, 1, 5].

Delete 5 makes the train [5, 4, 1, 5, 3] become [4, 1, 3].

DeleteFront make the train [1, 2, 3, 4] become [2, 3, 4].

 

DeleteRange 2 4 make the train [6, 5, 4, 3, 2, 1] become [6, 2, 1].

* Example 2: DeleteRange 2 4 will not affect the train [1, 2, 3] (since the index 4 is invalid)

* Example 3: DeleteRange 0 2 will not affect the train [1, 2, 3] (since the index 0 is invalid).

 

Swap makes the train [2, 6, 3] become [3, 6, 2].

 

The train is empty in the beginning. Given a series of instructions, please print the index of train carriages after all instructions are executed.

 

This is a partial judge problem, you're asked to implement 3 functions.

 

Hint: You can use the Print function to debug!

 

Input

The input consists of multiple instructions (1 ≤ number of instructions ≤ 105)

 

the index of each carriage is a positive integer and not greater than 102.

 

the num1 and the num2 (num1 ≤ num2) of the DeleteRange instruction are guaranteed two integers.

 

Output

The output only consists of a line denoting the train carriage indices after all the instructions.

 

It's guaranteed that the output consists of at least one carriage.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

13421.c

Partial Judge Header

13421.h

Tags




Discuss