void init(); 
void insert(int );
struct Node* listSearch(int );
void deleteNode(struct Node *);
void deleteFirst();
void deleteLast();
void deleteKey(int );
void print();
 
struct Node{
 
  int key;
  struct Node *prev;
  struct Node *next;
 
};
 
struct Node *NIL =NULL;
 
int main(){
 
  int sc,i,key;
  char c[10];
 
  init();
 
  scanf("%d",&sc);
 
  for(i = 0; i < sc; i++){
 
    scanf("%s",c);
 
    if((strcmp("insert",c)) == 0){
 
      scanf("%d",&key);
      insert(key);
     
 
    }
 
    else if((strcmp("delete",c)) == 0){
 
      scanf("%d",&key);
      deleteKey(key);
    }
 
    else if((strcmp("deleteFirst",c))==0){
 
      deleteFirst();
    }
 
    else if((strcmp("deleteLast",c))== 0){
 
       deleteLast();
 
    }
 
  }
 
  print();
 
  return 0;
 
}
 
void init(){
 
  NIL = (struct Node *)malloc(sizeof(struct Node));
 
  NIL->next  = NIL;
  NIL->prev = NIL;
 
}
 
void insert(int key){
 
  struct Node *x = (struct Node*)malloc(sizeof(struct Node));
 
 
  x -> key = key;
 
  x->next = NIL->next;
  NIL->next->prev = x;
 
  NIL->next = x;
 
  x->prev = NIL;
 
}
 
struct Node* listSearch(int key){
 
  struct Node *y = NIL->next;
 
 
  while(y != NIL && y->key != key){
 
    y = y->next;
 
  }
 
  return y;
 
}
 
void deleteNode(struct Node *x){
 
  if(x == NIL){
     
    return ;
   
  }
 
  x->prev->next = x->next;
  x->next->prev = x->prev;
 
   free(x);
 
   
}
 
void deleteFirst(){
 
  deleteNode(NIL->next);
 
}
 
void deleteLast(){
 
  deleteNode(NIL->prev);
 
}
 
void deleteKey(int key){
 
  deleteNode(listSearch(key));
}
 
void print(){
 
  struct Node *z = NIL->next;
 
  int x;
 
  while(1){
 
    if(z == NIL){
 
      break;
 
    }
 
    if(x++ > 0){
 
      printf(" ");
 
    }
 
    printf("%d", z->key);
 
    z = z->next;
 
  }
 
  printf("\n");
 
}