eolymp
Problems

Deque with error protection

Deque with error protection

Time limit 2 seconds
Memory limit 128 MiB

Implement the "deque" data structure. Write a program that contains the description of the deck and implement all the methods mentioned below. The program reads the sequence of commands and, depending on the command performs an operation. After each command, the program should print one line. Possible commands for the program are:

push\_front

Add (put) the element in front of the deque. The program must print ok.

push\_back

Add (put) the element in back of the deque. The program must print ok.

pop\_front

Remove the first element from the deque. The program must print its value.

pop\_back

Remove the last element from the deque. The program must print its value.

front

Give the value of the first element (not removing it). The program must print its value.

back

Give the value of the last element (not removing it). The program must print its value.

size

Print the number of elements in the deque.

clear

Clean the deque (delete all its elements) and print ok.

exit

The program must print bye and finish.

It is guaranteed that the number of elements in the deque during runtime is no more than 100. Before processing the operations pop\_front, pop\_back, front, back the program must check if the deque contains at least one element. If you run the operation pop\_front, pop\_back, front, back and the deque is empty, the program should print line error instead of integer value.

// Java OOP
class MyDeque // from problem 6128 Simple deque
{
  protected LinkedList<Integer> v;
  ...
}

class ErrorProtectedDeque extends MyDeque
{
  final static int ERROR = -2000000000;
  public int pop_front();  // in the cases of error, return ERROR
  public int pop_back();  // in the cases of error, return ERROR
  public int front(); // in the cases of error, return ERROR
  public int back();  // in the cases of error, return ERROR
}

Input data

Given in the problem statement. See sample input.

Output data

Given in the problem statement. See sample output.

Examples

Input example #1
front
back
pop_back
pop_front
exit

Output example #1
error
error
error
error
bye
Input example #2
push_back 1
back
exit
Output example #2
ok
1
bye