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

typedef struct _List{
	struct _List *prev,*next;
	long x;
}List;

List *head,*tail;
int flag=0;

void set();
void output();
List *generate(long);
void insertFirst(long);
void insertLast(long);
void delete(long);
void deleteFirst();
void deleteLast();
void deleteAll();

int main(void){
	int i,j=0;
	int n;
	long x;
	char op[15];

	set();
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",op);
		if(strcmp(op,"insert")==0){
			scanf("%ld",&x);
			insertFirst(x);
		}else if(strcmp(op,"delete")==0){
			scanf("%ld",&x);
			delete(x);
		}else if(strcmp(op,"deleteFirst")==0) deleteFirst();
		else if(strcmp(op,"deleteLast")==0) deleteLast();
	}

	output();
return 0;
}
void set(){
List *l;
l = generate(-1);
head = l;
tail = l;
return;
}
void output(){
	List *tmp;
	//List tmp = (List *)malloc(sizeof(List));
	if(flag == 0){
		return;
	}
	tmp = head;
	while(tmp != NULL){
		printf("%ld",tmp->x);
		if(tmp->next == NULL/*|| tmp->next->next == NULL*/) break;
		printf(" ");
		tmp = tmp->next;
	}
	printf("\n");
return;
}

List *generate(long x){
	List *p;
	p = (List *)malloc(sizeof(List));
	p->prev = NULL;
	p->next = NULL;
	p->x = x;
	return p;
}

void insertFirst(long x){
	List *p;
	p = generate(x);
	//first contents
	if(flag==0){
		tail = p;
		flag = 1;
	}else{
		head->prev = p;
		p->next = head;
	}
	head = p;
	return;
}
void insertLast(long x){
	List *p,*tmp;
	p = generate(x);
	//first contents
	if(flag==0){
		head = p;
		flag = 1;
	}else{
		p->prev = tail;
		tail->next = p;
	}
	tail = p;
	return;
}
void delete(long x){
	List *p;
	//List tmp = (List *)malloc(sizeof(List));
	if(flag == 0){
		return;
	}
	if(head->x ==x){
		deleteFirst(x);
		return;
	}
	p = head;
	while(p->x != x){
		if(p->next == NULL){
			return;
		}
		p = p->next;
	}
	if(p->next == NULL){
		deleteLast(x);
		return;
	}
	List *prev;
	prev = p->prev;
	List *next;
	next = p->next;
	free(p);
	prev->next = next;
	next->prev = prev;
return;
}
void deleteFirst(){
	if(flag==0) return;
	List *next = head->next;
	if(next == NULL){
		flag = 0;
		set();
	}else{
	next->prev = NULL;
	free(head);
	head = next;
	}
return;
}
void deleteLast(){
	if(flag==0) return;
	List *prev = tail->prev;
	if(prev == NULL){
		flag = 0;
		set();	
	}else{
		prev->next=NULL;
		free(tail);
		tail = prev;
	}
return;
}
void deleteAll(){
	List *tmp,*next;
	//List tmp = (List *)malloc(sizeof(List));
	if(flag == 0){
		return;
	}
	tmp = head;
	next = tmp->next;
	while(next != NULL){
		free(tmp);
		next = next->next;
		tmp = next;
	}
	set();
	flag = 0;
return;
}