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

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

void insert(int);
void deletekey(int);
NodePointer search(int);
void delete(NodePointer);

NodePointer nil;

int main()
{
  int i, n, keydata;
  char command[12];
  NodePointer x;

  //ダミーノードの作成
  nil = (NodePointer)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
  nil->key = -1;

  scanf("%d",&n);

  for(i = 0; i < n; i++) {
    scanf("%s",command);

    if(strcmp(command,"insert") == 0) {
      scanf("%d",&keydata);
      insert(keydata);
    }
    else if(strcmp(command,"delete") == 0) {
      scanf("%d",&keydata);
      deletekey(keydata);
    }
    else if(strcmp(command,"deleteFirst") == 0) delete(nil->next);
    else delete(nil->prev);
  }

  x = nil->next;
  printf("%d",x->key);
  x = x->next;
  while(x != nil) {
    printf(" %d",x->key);
    x = x->next;
  }
  printf("\n");


  x = nil->next->next;
  while(x != nil) {
    free(x->prev);
    x = x->next;
  }
  free(nil);

  return 0;
}

void insert(int keydata)
{
  NodePointer x;

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

  x->key = keydata;
  
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

void deletekey(int keydata)
{
  NodePointer x;

  if((x = search(keydata)) == nil) return;

  delete(x);
}

NodePointer search(int keydata)
{
  NodePointer x;

  x = nil->next;
  while(x != nil && x->key != keydata) {
    x = x->next;
  }
  
  return x;
}

void delete(NodePointer x)
{
  x->prev->next = x->next;
  x->next->prev = x->prev;
  free(x);
}



