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

typedef struct Node {
    int key;
    struct Node *prev;
    struct Node *next;
}node;

node *nil;

void init();
void insert(int);
void delete(node *);
void deleteFirst();
void deleteLast();
void printnode();
node *liserch(int);

int main(){
    int n,i,k;
    char c[12];

    scanf("%d",&n);

    init();

    for(i=0;i<n;i++){
        scanf("%s",c);
        
        if(strcmp("insert",c)==0){
          scanf("%d",&k);
          insert(k);  
        }

        else if(strcmp("delete",c)==0){
            scanf("%d",&k);
            delete(liserch(k));
        }

        else if(strcmp("deleteLast",c)==0){
            deleteLast();
        }

        else if(strcmp("deleteFirst",c)==0){
            deleteFirst();
        }
    }
    printnode();
    return 0;
}


void init(){

    nil=(node *)malloc(sizeof(node));
    nil->next=nil;
    nil->prev=nil;
}


void insert(int k){
    node *x;

    x=(node *)malloc(sizeof(node));
    x->key=k;
    x->next=nil->next;
    x->prev=nil;
    nil->next->prev=x;
    nil->next=x;
}


void delete(node *t){
    if(t==nil)return;
    t->next->prev=t->prev;
    t->prev->next=t->next;
    free(t);
}


node *liserch(int k){
    node *cur;

    cur=nil->next;
    
    while (cur->key!=k && cur!=nil){
        cur=cur->next;
    }
    return cur;
}


void deleteLast(){
    delete(nil->prev);
}


void deleteFirst(){
    delete(nil->next);
}


void printnode(){
    node *cur;

    cur=nil->next;
    
    while (cur!=nil){
        if(cur!=nil->next)printf(" ");
        printf("%d",cur->key);
        cur=cur->next;
    }
    printf("\n");
}
