#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 15

struct node{
  int key;
  struct node *prev, *next;
};

typedef struct node * Nodepointer;

void insert(int);
void delete(int);
void deleteFirst();
void deleteLast();
Nodepointer find(int);
void print(void);

Nodepointer head;
int cnt = 0;

int main(){
  int n, x;
  int i;
  char com[LEN];

  head = (Nodepointer)malloc(sizeof(struct node));
  head -> next = head;
  head -> prev = head;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf(" %s", com);
    if(strcmp(com, "insert") == 0){
      scanf(" %d", &x);
      //printf("%d\n", x);
      insert(x);
      //printf("%d\n", x);
    }
    else if(strcmp(com, "delete") == 0){
      scanf(" %d", &x);
      delete(x);
    }
    else if(strcmp(com, "deleteFirst") == 0) deleteFirst();
    else if(strcmp(com, "deleteLast") == 0) deleteLast();
  }

  print();
  
  return 0;
}

//末尾のノードのnextはhead
//head -> prev は末尾のノード

void insert(int x){
  Nodepointer newnode;
  newnode = (Nodepointer)malloc(sizeof(struct node));
  newnode -> key = x;
  newnode -> next = head -> next;
  head -> next -> prev = newnode;
  //printf("debug\n");
  head -> next = newnode;
  newnode -> prev = head;
  cnt++;
}

void delete(int x){
  Nodepointer delnode;
  if((delnode = find(x)) != NULL){
    if(delnode == head) return;
    //printf("debug\n");
    delnode -> prev -> next = delnode -> next;
    delnode -> next -> prev = delnode -> prev;
    free(delnode);
    cnt--;
  }
  else return;
}

void deleteFirst(){
  Nodepointer delnode;
  delnode = head -> next;
  if(delnode == head) return;
  delnode -> prev -> next = delnode -> next;
  delnode -> next -> prev = delnode -> prev;
  //printf("debug\n");
  free(delnode);
  cnt--;
}

void deleteLast(){
  Nodepointer delnode;
  delnode = head -> prev;
  if(delnode == head) return;
  delnode -> prev -> next = delnode -> next;
  delnode -> next -> prev = delnode -> prev;
  //printf("debug\n");
  free(delnode);
  cnt--;
}

Nodepointer find(int x){
  Nodepointer p;
  for(p = head->next; p != head; p = p -> next){
    if(p -> key == x) return p;
  }
  return NULL;
}

void print(){
  Nodepointer p;
  //printf("debug\n");
  for(p = head->next ;p->next != head; p = p->next ){
    printf("%d ", p -> key);
  }
  printf("%d\n", p -> key);
}

