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

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

typedef struct node * NodePointer;

void insert(int);
void delete(NodePointer);
void deleteFirst(void);
void deleteLast(void);
NodePointer search(int);

NodePointer nil;

int main(){
   
  int n,i,key;
  NodePointer m;
  NodePointer L;
  char order[12];
  
  nil=(NodePointer)malloc(sizeof(struct node));
  nil->next=nil;
  nil->prev=nil;

  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%s",order);
    if(order[0]=='i') {scanf("%d",&key);
      insert(key);}
    else if(order[0]=='d'&& order[6]=='F') {
      deleteFirst();
    }
    else if(order[0]=='d'&& order[6]=='L'){
      deleteLast();
    }
    else {scanf("%d",&key);
      delete(search(key));} 
  }

    for(m=nil->next;m!=NULL;m=m->next){
    if(m->next==NULL)printf("%d\n",m->key);
    else printf("%d ",m->key);
    }
   
  return 0;
}

void insert(int key){
  NodePointer x;
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}


void delete(NodePointer delnode){
  if(delnode==nil) return;
  delnode->prev->next = delnode->next;
  delnode->next->prev = delnode->prev;

  free(delnode);
}

void deleteFirst(void){
  delete(nil->next);
}

void deleteLast(void){
  delete(nil->prev);
}

NodePointer search(int k){
  NodePointer x;
  x = nil->next;
  while(x!=nil && x->key!=k){
    x = x->next;
  }
  return x;
}