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

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

  typedef struct node * Node;
  void make_node(void);
  void insert(int);
  void delete(int);
  void list(void);

  Node head;

  int main(){
    
    int  i;
    int  n;
    int  key;
    char order[15];
    Node x;
    
    make_node();
   
    scanf("%d",&n);
    for(i=0;i<n;i++){
    scanf("%s",order);
    if(strcmp(order,"insert")==0){
    scanf("%d",&key);
    insert(key);
    }
    else if(strcmp(order,"delete")==0){
    scanf("%d",&key);
    delete(key);
    }
   
    else if(strcmp(order,"deleteFirst")==0){
    x = head->next;
    x->prev->next = x->next;
    x->next->prev = x->prev;
    free(x);
    }
 
    else if(strcmp(order,"deleteLast")==0){
    x = head->prev;
    x->prev->next = x->next;
    x->next->prev = x->prev;
    free(x);
    }
   }
   list();
   return 0;
}
    void make_node(void){
    head = malloc(sizeof(struct node));
    head->next = head;
    head->prev = head;
    }

    void insert(int key){
   
    Node x;
   
    x = malloc(sizeof(struct node));
   
    x->next = head->next;
    head->next->prev = x;
    head->next = x;
    x->prev = head;
   
    x->key = key;
    }
    void delete(int key){
    Node x;
    for(x=head->next;x!=head;x=x->next){
    if(x->key == key){
    x->prev->next = x->next;
    x->next->prev = x->prev;
    free(x);
    break;
     }
    }
   }
void list(void){
   Node x;
   for(x=head->next;x!=head->prev;x=x->next){
   printf("%d ",x->key);
     }
   printf("%d",x->key);
   printf("\n");
}