#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
  int num;
  struct node *prev;
  struct node *next;
}node;
typedef struct node *d_l_list;
d_l_list head;
d_l_list last;
void insert(int);
void num_search_an_delete(int);
void delete(d_l_list);
void d_first();
void d_last();
void printnode();
int main(){
  int n;
  char command[12];
  int v;
  int i;
  head=malloc(sizeof(node));
  last=malloc(sizeof(node));
  head->num=last->num=0;
  head->next=last;
  last->prev=head;
  head->prev=last->next=NULL;
  d_l_list getnode(int);
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",command);
    if(!strcmp(command,"insert")){
      scanf("%d",&v);
      insert(v);
    }
    else if(!strcmp(command,"delete")){
      scanf("%d",&v);
      num_search_an_delete(v);
    }
    else if(!strcmp(command,"deleteFirst"))d_first();
    else if(!strcmp(command,"deleteLast"))d_last();
  }
  printnode();
  return 0;
}
d_l_list getnode(int x){
  d_l_list newnode;
  newnode=malloc(sizeof(node));
  newnode->num=x;
  newnode->prev=NULL;
  newnode->next=NULL;
  return newnode;
}
void insert(int v){
  d_l_list newnode=getnode(v);
  newnode->next=head->next;
  newnode->prev=head;
  head->next=newnode;
  newnode->next->prev=newnode;
}
void num_search_an_delete(int x){
  d_l_list searchnode;
  searchnode=head->next;
  while(searchnode!=last){
    if(searchnode->num==x){
      delete(searchnode);
      break;
    }
    searchnode=searchnode->next;
  }
  return;
}
void d_first(){
  d_l_list f_node=head->next;
  delete(f_node);
}
void d_last(){
  d_l_list l_node=last->prev;
  delete(l_node);
}
void delete(d_l_list del){
  d_l_list delprev=del->prev;
  d_l_list delnext=del->next;
  delnext->prev=del->prev;
  delprev->next=del->next;
  free(del);
}
void printnode(){
  d_l_list p_node;
  p_node=head->next;
  while(p_node!=last){
    printf("%d%c",p_node->num,((p_node->next==last)?'\n':' '));
    p_node=p_node->next;
  }
}

