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


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

//NodePointer
typedef struct node * NodePointer;

//function
NodePointer make1node(int);
//find item
NodePointer finditem(int);
//insert data
void insert(int);
//delete data
void delete(int);
//delete last data
void deleteLast(void);
//delete first data
void deleteFirst(void);

//print
void listprint(void);
//nil
NodePointer nil;

int main(){
 
  nil=make1node(0);
  int n,i;
  long num;
  char a[15];
  //load number of command
  scanf("%d",&n);
  //execute
  for(i=0;i<n;i++){
    //load command
    scanf("%s",a);

    //if insert,load data
    if(strcmp(a,"insert")==0){
      scanf("%ld",&num);
      insert(num);
    }
    //if delete load data

    else if(strcmp(a,"delete")==0){
      scanf("%ld",&num);
      delete(num);
    }


    else if(strcmp(a,"deleteFirst")==0) deleteFirst();
    else if(strcmp(a,"deleteLast")==0) deleteLast();
  }
  //print
  listprint();

  return 0;
}


NodePointer make1node(int keydata){
  NodePointer n;
  n=malloc(sizeof(struct node));
  n->key=keydata;
  n->next=n;
  n->prev=n;

  return n;
}

void insert(int value){
  NodePointer newnode;

  newnode=make1node(value);

  newnode->next=nil->next;

  newnode->next->prev=newnode;
 
  nil->next=newnode;

  newnode->prev=nil;



}

NodePointer finditem(int value){
  NodePointer n;

  n=nil->next;
  while(n!=nil &&n->key!=value){
    n=n->next;
  }
  if(n!=nil) return n;
  else return NULL;


}



void delete(int value){
  NodePointer n;
  if((n=finditem(value))!=NULL){

    n->prev->next=n->next;
    n->next->prev=n->prev;

    free(n);
  }
}

void listprint(void){
  NodePointer n;
  for(n=nil->next;n!=nil;n=n->next){
    if(n==nil->next){
    printf("%d",n->key);
    }
    else printf(" %d",n->key);
  }
  printf("\n");
}

void deleteFirst(void){
  NodePointer n;
  n=nil->next;
  
  n->prev->next=n->next;
  n->next->prev=n->prev;

  free(n);
}

void deleteLast(void){
  NodePointer n;
 
  n=nil->prev;
  
  n->prev->next=n->next;
  n->next->prev=n->prev;

  free(n);


}