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

/* Struct declaration */
struct node {
  int key;
  struct node *prev;
  struct node *next;
};
typedef struct node * NodePointer;

/* Prototype declaration */
void init(void);
void insert(int);
NodePointer search(int);
void delete(int);
void deleteFirst(void);
void deleteLast(void);
void listprint(void);


/* Global variable */
NodePointer dummy;


int main() {

  int i, n;
  char command[15];
  int x;

  dummy = (NodePointer)malloc(sizeof(struct node));
  init();

  /* Input and Process */
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%s", command);
    if(strcmp(command, "insert") == 0) {
      scanf("%d", &x);
      insert(x);
    }else if(strcmp(command, "delete") == 0) {
      scanf("%d", &x);
      delete(x);
    }else if(strcmp(command, "deleteFirst") == 0) {
      deleteFirst();
    }else if(strcmp(command, "deleteLast") == 0) {
      deleteLast();
    }
  }
  
  /* Output */
  listprint();

  return 0;
  
}

/* Initialize  Sentinel */
void init(void){
  dummy->prev = dummy;
  dummy->next = dummy;
}

/* Insert to Doubly Linked List */
void insert(int keydata) {
  NodePointer x;

  x = (NodePointer)malloc(sizeof(struct node));

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

  x->key = keydata;
  
}

/* Delete arbitrary data from Doubly Linked List */
void delete(int keydata) {
  NodePointer x;

  x = search(keydata);

  if(x != dummy) {
    x->prev->next = x->next;
    x->next->prev = x->prev;

    free(x);
  }
}

/* Search */
NodePointer search(int keydata) {
  NodePointer x;
  x = dummy->next;
  while((x != dummy) && (x->key != keydata)) 
    x = x->next;
  
  return x;
}

/* Output Doubly Linked List */
void listprint(void) {
  NodePointer x;
  x = dummy->next;
  while(x != dummy) {
    printf("%d", x->key);
    if(x != dummy->prev) printf(" ");
    x = x->next;
  }printf("\n");
  
}

/* Delete first data from Doubly Linked List */
void deleteFirst(void) {
  NodePointer x;
  x = dummy->next;

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

  free(x);
}

/* Delete last data from Doubly Linked List */
void deleteLast(void) {
  NodePointer x;
  x = dummy->prev;

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

  free(x);
}