#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  int number;
  struct node *next,*prev;
};
typedef struct node * nodepointer;
nodepointer search(int k);
nodepointer insert(int x);
void delete(int x);
nodepointer deleteF();
nodepointer deleteL();
void list();
nodepointer head;
nodepointer tail;
int main()
{
  int n,m,k=0,i,sum=0,u,x=0,num,ema;
  char com[100];
  head=malloc(sizeof(struct node));
  tail=malloc(sizeof(struct node));
  head->next=tail;
  head->prev=NULL;
  tail->next=NULL;
  tail->prev=head;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    ema=scanf("%s",com);
    if(ema==EOF)break;
    if(strcmp("deleteFirst",com)==0){
      deleteF();
      continue;
    }else if(strcmp("deleteLast",com)==0){
      deleteL();
      continue;
    }
    scanf("%d",&num);
    if(strcmp("insert",com)==0){
      if(insert(num)==NULL);//printf("already exist\n");
    }else if(strcmp("delete",com)==0){
      delete(num);//printf("originally nothing\n");
    }
  }
  list();
  free(tail);
  free(head);
  return 0;
}
nodepointer search(int k){
  nodepointer n;
  for(n=head;n->next!=tail;n=n->next){
    if(n->next->number==k)return n->next;
  }
  return NULL;
}
nodepointer insert(int x){
  nodepointer new;
  new=malloc(sizeof(struct node));
  new->number=x;
  new->next=head->next;
  head->next->prev=new;
  head->next=new;
  new->prev=head;
  return new;
}
void delete(int x){
  nodepointer n,del;
  if((n=search(x))!=NULL){
    n->prev->next=n->next;
    n->next->prev=n->prev;
    free(n); 
  }
}
nodepointer deleteL(){
  nodepointer n,del;
  if(head->next!=tail){
    n=tail->prev->prev;
    del=n->next;
    n->next=tail;
    tail->prev=n;
    free(del);
    return n;
  }else{
    return NULL;
  }
}
nodepointer deleteF(){
  nodepointer n,del;
  n=head;
  del=n->next;
  n->next=del->next;
  free(del);
  return n;
}
void list(){
  nodepointer n;
  for(n=head->next;n!=tail;n=n->next){
    printf("%d",n->number);
    if(n->next!=tail)printf(" ");
  }
  printf("\n");
}

