~/algor $ cat problems/navbat-dek-buyruqlari
Deque commands
Easy
1000 ms
128 MB
27%
A deque is a queue to which elements can be added and from which they can be removed at both ends. An empty deque and $n$ commands are given. Execute the commands in order.
push_front x— add the integer $x$ to the front,push_back x— to the back (nothing is printed);pop_front— remove the front element and print it,pop_back— the same for the back;front— print the front element without removing it,back— the same for the back;size— print the number of elements.
If the deque is empty, error is printed instead of pop_front, pop_back, front and back (the deque does not change).
Input
The first line contains a positive integer $n$. Each of the next $n$ lines contains one command.
Output
For every command except push_front and push_back, the answer on a separate line: an integer or error.
Note
$1 \le n \le 10^{5}$
$-10^{9} \le x \le 10^{9}$
at least one command prints an answer
Examples
Input #1
8 push_back 3 push_front 7 back push_back 5 pop_front front pop_back size
Output #1
3 7 3 5 1
Input #2
3 pop_back front size
Output #2
error error 0