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

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

void insert(int);
void delete(NodePointer);
void listprint(void);
NodePointer make_1node(int, NodePointer,NodePointer);

NodePointer head;
NodePointer tail;

int list_count=0;

int main(){
  NodePointer n;
  char command[12];
  int count,num,time=0,flag=0;
  char command_list[4][12]={{"insert"},{"delete"},{"deleteFirst"},{"deleteLast"}};
  head = make_1node(0,NULL,NULL);
  tail = make_1node(0,NULL,NULL);
  scanf("%d",&count);
  while(count>0){
    count--;
    scanf("%s",command);

    if(strcmp(command,command_list[0]) == 0){ //insert
      scanf("%d",&num);
      insert(num);
      list_count++;
    }

    else if(strcmp(command,command_list[1]) == 0){ // delete
      scanf("%d",&num);
      for(n = head->next;n != tail->next;n=n->next){
	if(n->key == num){
	  flag=1;
	  if(n == head->next){
	    head->next = n->next;
	    tail->next->next = head->next;
	    head->next->prev = tail->next;
	    delete(n);
	  }
	  else{
	    n->prev->next=n->next;
	    n->next->prev=n->prev;
	    delete(n);
	  }
	  break;
	}
      }
      if(n->key == num && flag == 0){
	tail->next = n->prev;
	tail->next->next = head->next;
	head->next->prev = tail->next;	
	delete(n);
      }
      flag=0;
    }  
    else if(strcmp(command,command_list[2]) == 0){ //deleteFirst
     n = head->next;
     head->next = n->next;
     tail->next->next = head->next;
     head->next->prev = tail->next;
     delete(n);
      
    }
    else if(strcmp(command,command_list[3]) == 0){ // deleteLast
      n = tail->next;
      tail->next = n->prev;
      tail->next->next = head->next;
      head->next->prev = tail->next;	
      delete(n);
    }
   
  }
  for(n=head->next;n != tail->next; n=n->next)printf("%d ",n->key);
  printf("%d\n",n->key);  
  
  return 0;
}
void insert(int num)
{
  NodePointer newnode;
  if(head->next == NULL){
  newnode = make_1node(num,NULL,NULL);
  head->next = newnode;
  tail->next = newnode;
  newnode->next=newnode;
  newnode->prev=newnode;  
  }
  else{
    newnode = make_1node(num,tail->next,head->next);
    head->next->prev = newnode;
    tail->next->next = newnode;
    head->next = newnode;
    
  }
    
}
NodePointer make_1node(int num, NodePointer pre,NodePointer nex)
{
  NodePointer n;
  
  if ((n = (NodePointer)malloc(sizeof(struct node))) == NULL) {
    printf("Error in memory allocation\n");
    exit(8);
  }
  n->key = num;
  n->next = nex;
  n->prev = pre;
  return n;
}
void delete(NodePointer n){
  if(list_count==1) {
    head->next = NULL;
    tail->next = NULL;
  }
  list_count--;
  free(n);
}
