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

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

typedef struct node *NodePointer;
NodePointer N;

void init(void); //???????????¢??°
void insert(int); //insert??¢??°
void delete(int); //delete??¢??°
void deleteFirst(void); //?????????????????????????????????
void deleteLast(void); //?????????????????????????????????
void deleteNode(NodePointer); //?????????????????????free??????
void Print(NodePointer); //?????????????????????

int main(void){

  int i,j,n,key;
  char a[12];
  struct node *NodePointer;
    
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s",a);
    if(strcmp(a,"insert") == 0){
      scanf("%d",&key);
      insert(key);
    }
    else if(strcmp(a,"delete") == 0){
      scanf("%d",&key);
      delete(key);
    }
    else if(strcmp(a,"deleteFirst") == 0){
      deleteFirst();
    }
    else if(strcmp(a,"deleteLast") == 0){
      deleteLast();
    }
  }
  Print(NodePointer);
  return 0;
}


void init(void){
  N = malloc(sizeof(struct node));
  N->next = N;
  N->prev = N;
}

void insert(int key){
  NodePointer p;
  p = malloc(sizeof(struct node));
  p->key = key;
  
  if(N->next == N){
    N->prev = p;
  }
  p->next = N->next;
  p->prev = N;
  N->next->prev = p;
  N->next = p;
}

void delete(int key){
  struct node *n;
  if(N->key == key){
    deleteFirst();
    return;
  }
  for(n=N->next;n!=N;n=n->next){

      if(n->key == key){
	deleteNode(n);
	return;
      }
    }
}

void deleteFirst(){
  NodePointer t = N->next;
  if ( t == N ) return;
  deleteNode(t);
}


void deleteLast(){
  NodePointer t = N -> prev;
  if(t == N) return;
  deleteNode(t);
}

void deleteNode(NodePointer t){
  if(t -> next == N){
    N->prev = t->prev;
    t->prev->next = N;
    free(t);
  }
  else if(t->prev == N){
    N->next = t->next;
    t->next->prev = N;
    free(t);
  }
  else{
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
  }
}