#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef struct Node{
    int key;
    struct Node *next;
    struct Node *prev;
}Node;
 
void insert(int);
void delete(Node *);
Node *search(int);

Node *nil;
main(){
    int n, tmpKey,i;
    char tmpStr[12];
    Node *p;
     
    nil = (Node *)malloc(sizeof(Node));
    nil -> next = nil -> prev = nil;
 
    scanf("%d", &n);
 
    for(i = 0;i < n;i++){
        scanf("%s",tmpStr);
        if(strcmp(tmpStr,"insert") == 0){
            scanf("%d",&tmpKey);
            insert(tmpKey);
        }
        else if(strcmp(tmpStr,"delete") == 0){
            scanf("%d",&tmpKey);
            delete(search(tmpKey));
        }
        else if(strcmp(tmpStr, "deleteFirst") == 0) delete(nil -> next);
        else if(strcmp(tmpStr, "deleteLast") == 0) delete(nil -> prev);
    }
 
    for (p = nil -> next;p -> next != nil;p = p -> next){
        printf("%d ",p -> key);
    }
    printf("%d\n",p -> key);
 
    return 0;
}
 
void insert(int key){
    Node *new;
 
    new = (Node *)malloc(sizeof(Node));
    new -> key = key;
    new -> next = nil -> next;
    new -> prev = nil;
    nil -> next = new;
    new -> next -> prev = new;
 
}
 
void delete(Node *ad){
    if (ad == NULL){
        return;
    }
    
    ad -> prev -> next = ad -> next;
    ad -> next -> prev = ad -> prev;
    free(ad);
}
 
Node *search(int key){
    Node *search;
    for (search = nil -> next;search != nil;search = search -> next){
        if (search -> key == key) return search;
    }
 
    return NULL;
}