#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct node *nodepointer;
struct node{
    int d;
    nodepointer next;
    nodepointer prev;
};

nodepointer makenode(int,nodepointer,nodepointer);
void insert(int);
void delete(int,int);
void listprint();

nodepointer head,tail;


int main(){
    head=makenode(-1,NULL,NULL);
    tail=makenode(-1,NULL,head);
    head->next=tail;
    int n,k,i;
    char com[12];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",com);
        if(strcmp(com,"insert")==0){
            scanf("%d",&k);
            insert(k);
        }
        else if(strcmp(com,"delete")==0){
            scanf("%d",&k);
            delete(k,0);
        }
        else if(strcmp(com,"deleteFirst")==0){
            delete(-1,1);
        }
        else{
            delete(-1,2);
        }
    }
    listprint();
}

nodepointer makenode(int keydata,nodepointer p_n,nodepointer p_p){
    nodepointer n;
    n=(nodepointer)malloc(sizeof(struct node));
    n->d=keydata;
    n->next=p_n;
    n->prev=p_p;
    return n;
}

void insert(int keydata){
    nodepointer n;
    n=makenode(keydata,head->next,head);
    head->next=n;
    n->next->prev=n;
}

void listprint(){
    int i=0;
    nodepointer p;
    for(p=head->next;p->next!=NULL;p=p->next,i++){
        if(i!=0) printf(" ");
        printf("%d",p->d);
    }
    printf("\n");
}
void delete(int keydata,int com){
    nodepointer p;
    if(com==0){
        for(p=head->next;p->next!=NULL;p=p->next){
            if(p->d==keydata){
                p->prev->next=p->next;
                p->next->prev=p->prev;
                free(p);
                break;
            }
        }  
    }
    else if(com==1){
        p=head->next;
        p->prev->next=p->next;
        p->next->prev=p->prev;
        free(p);
    }
    else{
        p=tail->prev;
        p->prev->next=p->next;
        p->next->prev=p->prev;
        free(p);
    }
}

