/*s1190073  Rina Sato
 File name: prog3c.c
 This is Doubly Linked List program.*/

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

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

typedef struct node * NodePointer;

NodePointer nil;

void init();
void insert(int);
void deleteFirst();
void deleteLast();
void delete(int);

int main(){
  NodePointer N;
  int key,n,i;
  char com[10];
  
  scanf("%d",&n);
  init();

  for(i = 0 ; i < n ; i++){
    scanf("%s",com);
    
    if(com[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(com[0] == 'd'){
      if(strlen(com) > 6){
	if(com[6] == 'F'){
	  deleteFirst();
	}
	else if(com[6] == 'L'){
 	  deleteLast();
	}
      }
      else {
	scanf("%d",&key);
	delete(key);

      }
    }
    
  }
  
  for(N = nil->next ; N->next != nil ; N->next){
    printf("%d",N->key);
  }
  return 0;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}
void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x -> next = nil -> next;
  x->prev = nil;
  nil->next->prev = x;
  nil->next = x; 
}

void deleteFirst(){
  NodePointer n;
  n = malloc(sizeof(struct node));
  nil->next = n->next;
  n->prev = nil;
  free(n);
}

void deleteLast(){
  NodePointer n;
  n = malloc(sizeof(struct node));
  n->prev->next = nil;
  nil->prev = n->prev;
  free(n);
}

void delete(int key){
  NodePointer n;
  n = malloc(sizeof(struct node));
  for(n = nil->next ; n->next != nil ; n->next){   
    if(n->key == key){
      n->next->prev = n->prev;
    }
break;
  }
  free(n);
}