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

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

NodePointer nil;

NodePointer listSearch(int key){
  // ここから
	
	NodePointer cur=nil->next;
	while(cur!= nil && cur->key!=key){
		cur=cur->next;
	}
	
	return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer 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 deleteNode(NodePointer t){
	// ここから
	if(t==nil) return;
	t->prev->next=t->next;
	t->next->prev=t->prev;
	free(t);

}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  //ここから
	
	deleteNode(nil->prev);
}

void delete(int key){
  //ここから
	
	deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
	
	// ここから
	x->next=nil->next;
	nil->next->prev=x;
	nil->next=x;
	x->prev=nil;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}

/*
void insert(int x[], int number, int cnt);
int delete(int x[], int number, int cnt);
void delete_F(int x[]);
void delete_L(int x[],int cnt);

int main(){
	int list[LEN],N,cnt=0,number,flag=0;
	char command[15];
	
	for(int i=0;i<LEN;i++){
		list[i]=0;
	}
	
	scanf("%d",&N);
	
	
	for(int i=0;i<N;i++){
		scanf("%s",command);
		if(strcmp(command,"insert")==0){
			scanf("%d",&number);
			insert(list,number,cnt);
			cnt++;
		}else if(strcmp(command,"delete")==0){
			flag=0;
			scanf("%d",&number);
			flag=delete(list,number,cnt);
			if(flag) cnt--;
		}else if(strcmp(command,"deleteFirst")==0){
			delete_F(list);
			cnt--;
		}else{
			delete_L(list,cnt);
			cnt--;
		}
		
		printf("%d",list[0]);
		for(int j=1;j<cnt;j++){
			printf(" %d",list[j]);
		}
		printf("\n");
		
	}
	
	printf("%d",list[cnt-1]);
	for(int j=cnt-2;j>=0;j--){
		printf(" %d",list[j]);
	}
	printf("\n");
	
  return 0;
}

void insert(int x[], int number, int cnt){
	
	x[cnt]=number;

}

int delete(int x[], int number, int cnt){
	
	int j=0;
	if(number==x[cnt-1]) return 1;
	for(int i=cnt-2;i>=0;i--){
		if(number==x[i]){
			for(j=i;j<cnt-1;j++){
				x[j]=x[j+1];
			}
			return 1;
		}
	}
	
	return 0;
}
void delete_F(int x[]){
	
	;
	
}
void delete_L(int x[],int cnt){
	for(int i=0;i<cnt-1;i++){
		x[i]=x[i+1];
	}
}
*/
