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

void init(); //ノードの初期化
void insert(int ); //ノードの追加
struct Node* listSearch(int );
void deleteNode(struct Node *);
void deleteFirst();
void deleteLast();
void deleteKey(int );
void print();

struct Node{

  int key;
  struct Node *prev;
  struct Node *next;

};

struct Node *NIL =NULL;

int main(){

  int sumcommand,i,key;
  char command[10];

  init();

  scanf("%d",&sumcommand);

  for(i = 0; i < sumcommand; i++){

    scanf("%s",command);

    if((strcmp("insert",command)) == 0){

      scanf("%d",&key);
      insert(key);
    

    }

    else if((strcmp("delete",command)) == 0){

      scanf("%d",&key);
      deleteKey(key);
    }

    else if((strcmp("deleteFirst",command))==0){

      deleteFirst();
    }

    else if((strcmp("deleteLast",command))== 0){

       deleteLast();

    }

  }

  print();

  return 0;

}

void init(){

  NIL = (struct Node *)malloc(sizeof(struct Node));

  NIL->next  = NIL;
  NIL->prev = NIL;

}

void insert(int key){

  struct Node *x = (struct Node*)malloc(sizeof(struct Node));


  x -> key = key;

  x->next = NIL->next;
  NIL->next->prev = x;

  NIL->next = x;

  x->prev = NIL;

}

struct Node* listSearch(int key){

  struct Node *y = NIL->next;


  while(y != NIL && y->key != key){

    y = y->next;

  }

  return y;

}

void deleteNode(struct Node *x){

  if(x == NIL){
    
    return ;
  
  }

  x->prev->next = x->next;
  x->next->prev = x->prev;

   free(x);

  
}

void deleteFirst(){

  deleteNode(NIL->next);

}

void deleteLast(){

  deleteNode(NIL->prev);

}

void deleteKey(int key){

  deleteNode(listSearch(key));
}

void print(){

  struct Node *z = NIL->next;

  int x;

  while(1){

    if(z == NIL){

      break;

    }

    if(x++ > 0){

      printf(" ");

    }

    printf("%d", z->key);

    z = z->next;

  }

  printf("\n");

}