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

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

typedef struct node * NodePointer;

void insert(NodePointer,NodePointer);
void delete(NodePointer,NodePointer);
void deleteFirst(NodePointer,NodePointer);
void deleteLast(NodePointer,NodePointer);

NodePointer nil;

int main(){
   
  int n,i;
  NodePointer m;
  NodePointer L;
  char order[15];
  int p,q;
  
  nil=(NodePointer)malloc(sizeof(struct node));
  nil->next=nil;
  nil->prev=nil;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%s",order);

    if(order[0]=='i') {scanf("%d%d%d",&p,&L->key,&q);
      insert(nil,L);}
    else if(order[0]=='d'&& order[6]=='F') {
          scanf("%d",&p);
          deleteFirst(nil,L);
    }
    else if(order[0]=='d'&& order[6]=='L'){
          scanf("%d",&p);
          deleteLast(nil,L);
    }
    else {scanf("%d%d%d",&p,&L->key,&q);
      delete(nil,L);} 
  }

  for(m=nil->next;m!=NULL;m=m->next){
    if(m->next==NULL)printf("%d\n",m->key);
    else printf("%d ",m->key);
    }
   
  return 0;
}

void insert(NodePointer nil,NodePointer x){

  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}


void delete(NodePointer nil,NodePointer x){
  
  x->prev->next = x->next;
  x->next->prev = x->prev;
}

void deleteFirst(NodePointer nil,NodePointer x){
  nil->next=x->next;
  x->next->prev=nil;
}

void deleteLast(NodePointer nil,NodePointer x){
  NodePointer n,delnode;
  for(n=nil->next;n!=NULL;n=n->next){}
     delnode=n;
     n->prev->next=NULL;
}