#K84607. Perform Operations on a Deque

    ID: 36457 Type: Default 1000ms 256MiB

Perform Operations on a Deque

Perform Operations on a Deque

This problem asks you to simulate a deque (double-ended queue) with a series of operations. You will be given a number of commands that can modify the deque by appending or removing elements from either the left or right end.

The operations are defined as follows:

  • append x: Append integer \(x\) to the right end of the deque.
  • appendleft x: Append integer \(x\) to the left end of the deque.
  • pop: Remove an element from the right end of the deque. If the deque is empty, do nothing.
  • popleft: Remove an element from the left end of the deque. If the deque is empty, do nothing.

Your task is to execute the given commands in order and then output the final state of the deque. The final state should be printed as a sequence of integers separated by spaces. If the deque is empty, print an empty line.

inputFormat

The input is given via standard input (stdin) in the following format:

n
command1
command2
... 
commandn

Where n is a non-negative integer representing the number of commands. Each subsequent line is a command as described above.

outputFormat

Output the final state of the deque as a sequence of integers separated by a space on one line (stdout). If the deque is empty, print an empty line.

## sample
5
append 1
append 2
appendleft 3
pop
popleft
1

</p>