// editor4
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct deq
{
    int data;
    struct deq*next,*prev;
}node;

node *front=NULL,*rear=NULL;

node* create(int n)
{
    node *nd=(node*)malloc(sizeof(node));
    nd->data=n;
    nd->next=nd->prev=NULL;
    return nd;
}
void insfront(int n)
{
    node *nd=create(n);
    if(front==NULL)
    {
        front=rear=nd;
    }
    else
    {
        nd->next=front;
        front->prev=nd;
        front=nd;
    }
}
void insrear(int n)
{
    node *nd=create(n);
    if(front==NULL)
    {
        front=rear=nd;
    }
    else
    {
        rear->next=nd;
        nd->prev=rear;
        rear=nd;
    }
}
void delfro()
{
    node *temp=front;
    front=front->next;
    //front->prev=NULL;
    printf("\n%d",temp->data);
    free(temp);
}
void delrer()
{
    node *temp=rear;
    rear->prev->next=NULL;
    rear=rear->prev;
    printf("\n%d",temp->data);
    free(temp);
}



int main()
{
    int n,cnt=0;
    scanf("%d",&n);
    if(n<=0)
    {
        printf("\nDequeue is full");
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        int data;
        char ops[20];
        scanf("%s",ops);
        scanf("%d",&data);
        if(!strcmp("insertFront",ops))
        {
            insfront(data);
            ++cnt;
        }
        
        if(!strcmp("insertLast",ops))
        {
            insrear(data);
            ++cnt;
        }
        if(!strcmp("deleteFront",ops))
        {
            if(cnt<=0)
            {
                printf("Deque is empty")
            }
            else
            {
            delfro();
            }
        }
        if(!strcmp("deleteLast",ops))
        delrer();
        if(!strcmp("getFront",ops))
        printf("\n%d",front->data);
        if(!strcmp("getLast",ops))
        printf("\n%d",rear->data);
        if(!strcmp("isEmpty",ops))
        {
            if(front==NULL)
            {
                printf("\ntrue");
            }
            else
            {
                printf("\nfalse");
            }
        }
        if(!strcmp("isFull",ops))
        {
            if(cnt==n)
            {
                printf("\ntrue");
            }
            else
            {
                printf("\nfalse");
            }
        }
    }
}