import java.util.*;
class deque{
private static final int Size = 200000;
int start, end;
int [] folder = new int[Size] ;
deque(){
start = end = Size/2;
}
void push_front(int var){
folder[--start] = var;
}
void push_back(int var){
folder[end++] = var;
}
void pop_front(){
System.
out.
println(folder
[start
++]); }
void pop_back(){
System.
out.
println(folder
[--end
]); }
void front(){
System.
out.
println(folder
[start
]); }
void back(){
System.
out.
println(folder
[end
-1]); }
void size(){
System.
out.
println(end
-start
); }
void clear(){
start = end = Size/2;
}
};
class Main
{
{
Scanner scan
= new Scanner
(System.
in); deque deq = new deque();
while (scan.hasNext()){
S = scan.next();
if (S.equals("push_front")) deq.push_front(scan.nextInt());
else if (S.equals("push_back")) deq.push_back(scan.nextInt());
else if (S.equals("pop_front")) deq.pop_front();
else if (S.equals("pop_back")) deq.pop_back();
else if (S.equals("front")) deq.front();
else if (S.equals("back")) deq.back();
else if (S.equals("size")) deq.size();
else if (S.equals("clear")) deq.clear();
else if (S.equals("exit")){
}
}
}
}
aW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgZGVxdWV7CiAgICBwcml2YXRlIHN0YXRpYyBmaW5hbCBpbnQgU2l6ZSA9IDIwMDAwMDsKICAgIGludCBzdGFydCwgZW5kOwogICAgaW50IFtdIGZvbGRlciA9IG5ldyBpbnRbU2l6ZV0gOwogICAgCiAgICBkZXF1ZSgpewogICAgICAgIHN0YXJ0ID0gZW5kID0gU2l6ZS8yOwogICAgfQogICAgdm9pZCBwdXNoX2Zyb250KGludCB2YXIpewogICAgICAgIGZvbGRlclstLXN0YXJ0XSA9IHZhcjsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIm9rIik7CiAgICB9CiAgICB2b2lkIHB1c2hfYmFjayhpbnQgdmFyKXsKICAgICAgICBmb2xkZXJbZW5kKytdID0gdmFyOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigib2siKTsKICAgIH0KICAgIHZvaWQgcG9wX2Zyb250KCl7CiAgICAJU3lzdGVtLm91dC5wcmludGxuKG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