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

struct Node{
  int x;
  struct Node *prev;
  struct Node *next;
};

void insert(int);
void delete(int);
void deleteFirst();
void deleteLast();
void display();
void release();

struct Node head;

int main(void){
  int n;
  char input[20];
  int inputx;

  head.prev = &head;
  head.next = &head;

  scanf("%d", &n);

  while((scanf("%s", input)) != EOF){
    if(strcmp(input, "insert") == 0){
      scanf("%d", &inputx);
      insert(inputx);
    }else if(strcmp(input, "delete") == 0){
      scanf("%d", &inputx);
      delete(inputx);
    }else if(strcmp(input, "deleteFirst") == 0){
      deleteFirst();
    }else if(strcmp(input, "deleteLast") == 0){
      deleteLast();
    }else if(strcmp(input, "display") == 0){
      display();
    }
  }
  release();
  return 0;
}

void insert(int input){
  struct Node *p, *prev, *next;

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

  prev = &head;
  next = head.next;
  p->x = input;
  p->prev = prev;
  p->next = next;
  next->prev = p;
  prev->next = p;

  //printf("insert %d\n", input);
}

void delete(int input){
  struct Node *p, *prev;

  prev = &head;

  if(head.next != &head){
    for(p = head.next; p != &head; p = p->next){
      if(p->x == input){
        if(p->next != &head){
          prev->next = p->next;
          p->next->prev = prev;

          //printf("delete %d\n", input);
          free(p);
          return;
        }

        prev->next = &head;
        head.prev = prev;
        //printf("delete %d\n", input);
        free(p);
        return;
      }

      prev = p;
    }
  }
}

void deleteFirst(){
  struct Node *p, *prev;

  prev = &head;
  p = head.next;
  prev->next = p->next;
  p->next->prev = prev;

  //printf("deleteFirst\n");
  free(p);
  return;
}

void deleteLast(){
  struct Node *p, *prev;

  if(head.next == &head){
    return;
  }

  p = head.prev;
  prev = p->prev;
  prev->next = &head;
  head.prev = prev;

  //printf("deleteLast\n");
  free(p);
  return;
}

void display(){
  struct Node *p;

  if(head.next == &head) return;

  for(p = head.next; p != &head; p=p->next){
    printf("%d ", p->x);
  }
  printf("\n");
}

void release(){
  struct Node *next, *del;

  next = head.next;

  display();
  while(next != &head){
    del = next;
    next = next->next;

    free(del);
  }
}