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

typedef struct _node_t {
	int key;
	struct _node_t *prev,*next;
} node_t;

void insert_front(node_t *_head,int _key) {
	node_t *new_node = (node_t*)malloc(sizeof(node_t));
	new_node->key = _key;
	new_node->prev = _head;
	new_node->next = _head->next;
	_head->next->prev = new_node;
	_head->next = new_node;
}

void delete_key(node_t *_head,node_t *_tail,int _key) {
	node_t *curr = _head->next;
	while (curr != _tail) {
		if (curr->key == _key) {
			curr->prev->next = curr->next;
			curr->next->prev = curr->prev;
			free(curr);
			break;
		}
		curr = curr->next;
	}
}

void delete_last(node_t *_tail) {
	node_t *delete_node = _tail->prev;
	_tail->prev->prev->next = _tail;
	_tail->prev = _tail->prev->prev;
	free(delete_node);
}

void output_list(node_t *_head,node_t *_tail) {
	node_t *node = _head->next;
	while (node != _tail) {
		printf("%d",node->key);
		printf(node->next == _tail ? "\n" : " ");
		node = node->next;
	}
}

int main(void) {
	int n;
	int i;
	char command[12];
	int key;
	node_t *head = (node_t*)malloc(sizeof(node_t));
	node_t *tail = (node_t*)malloc(sizeof(node_t));
	head->prev = tail->next = NULL;
	head->next = tail;
	tail->prev = head;
	scanf("%d",&n);
	for (i = 0;i != n;++i) {
		scanf("%s",command);
		if (strcmp(command,"insert") == 0) {
			scanf("%d",&key);
			insert_front(head,key);
		} else if (strcmp(command,"delete") == 0) {
			scanf("%d",&key);
			delete_key(head,tail,key);
		} else if (strcmp(command,"deleteFirst") == 0) {
			delete_key(head,tail,head->next->key);
		} else { // command == "deleteLast"
			delete_last(tail);
		}
	}
	output_list(head,tail);
	while (head->next != tail) {
		delete_key(head,tail,head->next->key);
	}
	free(head);
	free(tail);
	return 0;
}