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

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

NodePointer make_lnode(int , NodePointer, NodePointer );
void listprint(void);
NodePointer finditem(int);
void insert(int);
void delete(int);
void deleteFirst();
void deleteLast();

NodePointer head, tail;

int main(){
  int i, num, val, n;
  char str[200][20];

  head = tail = make_lnode(0, NULL, NULL);
    
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",str[i]);
    if(strcmp(str[i],"insert")==0){
      scanf("%d",&val);
      insert(val);
    }
    else if(strcmp(str[i],"delete")==0){
      scanf("%d",&val);
      delete(val);
    }
    else if(strcmp(str[i],"deleteFirst")==0){
      deleteFirst();
    }
    else {
      deleteLast();
    }
  }
  listprint();
  
  return 0;
}
NodePointer make_lnode(int keydata, NodePointer prev, NodePointer next){
  NodePointer n;

  if((n = (NodePointer)malloc(sizeof(struct node))) == NULL){
    printf("Error in memory allocation\n");
    exit(8);
  }
  n->key = keydata;
  n->next = next;
  n->prev = prev;
  return n;
}
void listprint(void){
  NodePointer n;
  int i;

  for(n = head->next; n != tail; n = n->next){
    printf("%d ",n->key);
  }
  printf("%d",tail->key);
  printf("\n");
}
NodePointer finditem(int value){
  NodePointer n;
  static int i=0;

  for(n = head; n->next != tail; n = n->next){
    if(n->next->key == value) return n;
  }
   if(n->next->key == value) return n;
  return NULL;
}
void insert(int keydata){
  NodePointer newnode;

  static int i=0;

   if(i==0){

     tail->key = keydata;
    tail->prev = head;
    head->next = tail;
    i++;
  }
     else if(i ==1){
       newnode = make_lnode(keydata, head, tail);
       tail->prev = newnode;
       head->next = newnode;
       i++;
       }
 else {
    newnode = make_lnode(keydata, head, head->next);
    newnode->next->prev = newnode;
    head->next = newnode;
    }
}
void deleteFirst(){

  NodePointer delnode, n;
  n = head;
  delnode = n->next;
  n->next = delnode->next;
  n->next->prev = head;
  free(delnode);
}
void deleteLast(){

  NodePointer delnode, n;

  n = tail;
  delnode = n;
  tail = n->prev;

  free(delnode);
}
void delete(int keydata){
  NodePointer n, delnode;
  if((n = finditem(keydata))!=NULL){
    if(n->next == tail){
      deleteLast();
    }
    else if(n->next == head->next){
      deleteFirst();
    }
    else{
      delnode = n->next;
      n->next = delnode->next;
      n->next->prev = n;
      free(delnode);
    }
  }
}