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

//リスト用構造体定義
struct Node {
  struct Node *prev;
  struct Node *next;
  int key;
};

//リストの先頭を定義
struct Node *nil;

//命令を行う関数の宣言
struct Node* listSearch(int);
void init();
void insert(int);
void deleteNode(struct Node*);
void deleteFirst();
void deleteLast();
void deleteKey(int);
void printList();

int main()
{
  int i,n,key;
  char str[20]; //命令判定用
  scanf("%d",&n);
  init();

  for(i = 0; i < n; i++) {
    scanf("%s %d",str,&key);
    if(strcmp(str,"insert") == 0) {
      insert(key);
    }
    else if(strcmp(str,"delete") == 0) {
      deleteKey(key);
    }
    else if(strcmp(str,"deleteFirst") == 0) {
      deleteFirst();
    }
    else if(strcmp(str,"deleteLast") == 0) {
      deleteLast();
    }
    else printf("error\n");
  }//命令

  printList();
  return 0;
}

struct Node* listSearch(int key) {
  struct Node *cur = nil->next;
  while ( cur != nil && cur->key != key ) {
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = (struct Node *)malloc(sizeof(struct Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList() {
  struct Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if ( cur == nil ) break;
    if ( isf++ > 0 ) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

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;
  
}

void deleteNode(struct Node *t) {
  if (t == nil) return; //t=nilの時処理しない
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}