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

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

struct Node *search(int);
void print();
void insert(int);
void delete(struct Node *);
void init(void);

struct Node *head;

int main(){
  int num,i,numcom;
  char command[20];
  
  struct Node *node;

  
  scanf("%d",&numcom);
  init();
  for(i=0;i<numcom;i++){
    scanf("%s",command);
    
    if(command[0]=='i'){
      scanf("%d",&num);
      insert(num);
      
    }
    else if(command[0]=='d'){
      if(strlen(command)>6){
	if(command[6]=='F'){
	  
	  delete(head->next);
	}
	 if(command[6]=='L'){
	   
	   delete(head->prev);
	 }
      }
	 else{
	   scanf("%d",&num);
	   node=search(num);
	   if(node==head) continue;
	   if(node==head) head=node->next;
	   delete(node);
	 }
      }
    
  }
   
    
    

  print();
  return 0;
}

struct Node * search(int num){
  struct Node *node;
  node=head->next;
  while(node!=head && node->key!=num) node=node->next;
  return node;
}

void print(){
  struct Node *node=head->next;
  int first=0;
  while(1){
    if(node==head) break;
    if(first>0) printf(" ");
    printf("%d",node->key);
   
    node=node->next;
    first++;
  }
  printf("\n");
}

void insert(int num){
  struct Node *node;
  node=malloc(sizeof(struct Node));
  node->key=num;
  node->next=head->next;
  head->next->prev=node;
  head->next=node;
  node->prev=head;
  
}

void delete(struct Node *node){
  if(node==head) return;
  if(node->prev!=NULL) node->prev->next=node->next;
  if(node->next!=NULL) node->next->prev=node->prev;
  free(node);
}

void init(){
  head=malloc(sizeof(struct Node));
  head->next=head;
  head->prev=head;
}

  

