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

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

typedef  struct node *Akkarin;
Akkarin nil;

Akkarin listSearch(int key){
  Akkarin x,y;

  y = nil;
  x = y->next;

  while(x != nil){
    if(x->key == key){
      return y;
    }
    y = x;
    x = y->next;
  }
  return NULL;
}


void display(){
  Akkarin cur = nil->next;
  int isf = 1;

  while(1){
    if(cur == nil) break;
    if(isf == 0) printf(" ");
    printf("%d" ,cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteFirst(){
  Akkarin x,y;

  x = nil->next;
  y = x->next;
  y->prev = nil;
  nil->next = y;
  free(x);
}

void deleteLast(){
  Akkarin x,y;

  x = nil->prev;
  y = x->prev;
  y->next = nil;
  nil->prev = y;
  free(x);
}

void deletee(int key){
  Akkarin x,y,z;

  if(nil->next->key == key){
    deleteFirst();
    return;
  }

  x = listSearch(key);
  if(x == NULL){
    return;
  }
  z = x->next;

  y = x->next->next;
  x->next = y;
  y->prev = x;

  free(z);
}

void insert(int key){
  Akkarin x,y;
  x = malloc(sizeof(struct node));
  x->key = key;

  y = nil->next;
  nil->next = x;
  x->prev = nil;
  x->next = y;
  y->prev = x;
}

int main(int argc, char* argv[])
{
	int n, i;
	scanf("%d", &n);
	int sss;
	char op[30];
    nil = malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
    nil->key = -1;
    for(i=0; i<n; i++){
        scanf("%s", op);
        if(strcmp(op,"insert") == 0){
            scanf("%d",&sss);
            insert(sss);

        }
        else if(strcmp(op,"delete") == 0){
            scanf("%d",&sss);
            deletee(sss);

        }
        else if(strcmp(op,"deleteFirst") == 0){
           deleteFirst();
        }
        else if(strcmp(op,"deleteLast") == 0){
            deleteLast();
           // printf("%d", j);
        }
    }
	display();
	return 0;
}
