#D1238. Deque
Deque
Deque
For a dynamic array of integers, perform a sequence of the following operations:
- push(, ): Add element at the begining of , if . Add element at the end of , if .
- randomAccess(): Print element .
- pop(): Delete the first element of , if . Delete the last element of , if .
is a 0-origin array and it is empty in the initial state.
Constraints
- the size of
Input
The input is given in the following format.
:
Each query is given by
0
or
1
or
2
where the first digits 0, 1 and 2 represent push, randomAccess and pop operations respectively.
randomAccess and pop operations will not be given for an empty array.
Output
For each randomAccess, print in a line.
Example
Input
11 0 0 1 0 0 2 0 1 3 1 0 1 1 1 2 2 0 2 1 0 0 4 1 0 1 1
Output
2 1 3 4 1
inputFormat
Input
The input is given in the following format.
:
Each query is given by
0
or
1
or
2
where the first digits 0, 1 and 2 represent push, randomAccess and pop operations respectively.
randomAccess and pop operations will not be given for an empty array.
outputFormat
Output
For each randomAccess, print in a line.
Example
Input
11 0 0 1 0 0 2 0 1 3 1 0 1 1 1 2 2 0 2 1 0 0 4 1 0 1 1
Output
2 1 3 4 1
样例
11
0 0 1
0 0 2
0 1 3
1 0
1 1
1 2
2 0
2 1
0 0 4
1 0
1 1
2
1
3
4
1
</p>