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

typedef struct key_node_tag{
	int key;
	struct key_node_tag *prev;
	struct key_node_tag *next;
} key_node_contents;

typedef struct {
	key_node_contents dammy;
} key_list_contents;

typedef struct {
} *key_list;

key_list key_list_new(){
	key_list_contents *listc = malloc(sizeof(key_list_contents));
	listc->dammy.prev = &listc->dammy;
	listc->dammy.next = &listc->dammy;
	return (key_list)listc;
}

int key_list_insert(key_list list, int x){
	key_list_contents *listc = (key_list_contents*)list;
	key_node_contents *node = malloc(sizeof(key_node_contents));

	node->key = x;
	node->prev = &listc->dammy;
	node->next = listc->dammy.next;
	listc->dammy.next->prev = node;
	listc->dammy.next = node;
	
	return 0;
}

int key_list_delete(key_list list, int x){
	key_list_contents *listc = (key_list_contents*)list;
	key_node_contents *pdammy = &listc->dammy,
			  *node = pdammy->next;
	
	while(node != pdammy){
		if(node->key == x){
			node->prev->next = node->next;
			node->next->prev = node->prev;
			free(node);
			return 0;
		}
		node = node->next;
	}
	
	return -1;
}

int key_list_delete_first(key_list list){
	key_list_contents *listc = (key_list_contents*)list;
	key_node_contents *node = listc->dammy.next;

	if(node == &listc->dammy){
		return -1;
	}
	node->next->prev = node->prev;
	node->prev->next = node->next;
	free(node);

	return 0;
}

int key_list_delete_last(key_list list){
	key_list_contents *listc = (key_list_contents*)list;
	key_node_contents *node= listc->dammy.prev;

	if(node == &listc->dammy){
		return -1;
	}
	node->next->prev = node->prev;
	node->prev->next = node->next;
	free(node);

	return 0;
}

int key_list_print(key_list list){
	key_list_contents *listc = (key_list_contents*)list;
	key_node_contents *pdammy = &listc->dammy,
			  *node = pdammy->next;
	int flag_init = 1;

	while(node != pdammy){
		if(flag_init){
			flag_init = 0;
			printf("%d", node->key);
		}else{
			printf(" %d", node->key);
		}
		node = node->next;
	}
	printf("\n");

	return 0;
}

int key_list_do_query(key_list list, char *query_str){
	int x;

	if(0 == strcmp(query_str, "insert")){
		scanf("%d", &x);
		key_list_insert(list, x);
		return 0;
	}else if(0 == strcmp(query_str, "delete")){
		scanf("%d", &x);
		key_list_delete(list, x);
		return 0;
	}else if(0 == strcmp(query_str, "deleteFirst")){
		key_list_delete_first(list);
		return 0;
	}else if(0 == strcmp(query_str, "deleteLast")){
		key_list_delete_last(list);
		return 0;
	}

	return -1;
}

int key_list_delete_all(key_list list){
	while(0 == key_list_delete_first(list)){}
	return 0;
}

int main(void){
	key_list list = key_list_new();
	int n, i;
	char query_str[16];

	scanf("%d", &n);
	for(i=0; i<n; ++i){
		scanf("%s", query_str);
		key_list_do_query(list, query_str);
	}
	key_list_print(list);
	key_list_delete_all(list);

	return 0;
}