13391 - Domo the Train Conductor   

Description

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

 

There are five instructions below with the description:

 

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. 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].

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 these 5 functions.

 

If you get a TLE:

Try to use the pointer head and back wisely, which can make the AddFront and AddBack instructions faster!

 

If you get an MLE:

Remember to free the nodes you've deleted!

 

Input

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

 

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

 

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

13391.c

Partial Judge Header

13391.h

Tags




Discuss