Олимпиадный тренинг

Задача 38605. Dec with error protection


Задача

Темы: Дек
Implement the "dec" data structure.  Write a program containing a description of the deck and simulating the operation of the deck, implementing all the methods indicated here. The program reads a sequence of commands and, depending on the command, performs one or another operation. After executing each command, the program should print one line. Possible commands for the program:

push_front
Add (put) a new element to the beginning of the deck. The program should print ok.

push_back
Add (put) a new element to the end of the deck. The program should print ok.

pop_front
Extract the first element from the deque. The program should output its value.

pop_back
Extract the last element from the deque. The program should output its value.

front
Get the value of the first element (without removing it). The program should output its value.

back
Get the value of the last element (without removing it). The program should output its value.

size
Display the number of elements in the deck.

clear
Clear deque (remove all elements from it) and output ok.

exit
The program should print bye and exit.
It is guaranteed that the number of elements in the deck does not exceed 100 at any time. Before executing the operations pop_front, pop_back, front, back, the program must check whether the deck contains at least one element. If the input contains operations pop_front, pop_back, front, back, and at the same time the deque is empty, then the program should output the string error instead of a numeric value.

Input
Deck control commands are entered, one per line.

Imprint
It is required to display the log of the deck, one message per line
Examples
# Input Output
1 push_back 1
back
exit
ok
1
bye
2 size
push_back 1

push_back 2

push_front 3

exit
0
ok
1
ok
2
ok
3
bye