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

typedef struct node {
int value;
struct node* next;
struct node* prev;
} node_t;

int n, num = 0;
node_t* head = NULL;
node_t* last = NULL;

node_t* current = NULL;

node_t* searchList(int);
node_t* createNode(int);
void insertToList(node_t*);
void deleteNode(node_t*);
void printList();

int main() {
	scanf("%d", &n);

	char tempCmd[15];
	int tempValue;
	for (int i = 0; i < n; i++) {
		scanf("%s", tempCmd);
		if (strcmp(tempCmd, "insert") == 0) {
			scanf("%d", &tempValue);
			node_t* insert = createNode(tempValue);
			insertToList(insert);
			num++;
			if (num == 1) last = insert;
		}
		else {
			node_t* delNode = NULL;
			if (strcmp(tempCmd, "delete") == 0) {
				scanf("%d", &tempValue);
				delNode = searchList(tempValue);
			}
			else if (strcmp(tempCmd, "deleteFirst") == 0) {
				delNode = head;
			}
			else {
				delNode = last;
			}

			if (delNode == last && delNode != head) last = last->prev;
			if(delNode == head) head = head->next;
			if(delNode != NULL) deleteNode(delNode);
			num--;
		}
	}
	printList();
	return 0;
}

node_t* searchList(int key) {
	current = head;
	while (current != NULL && current->value != key) {
		current = current->next;
	}
	return current;
}

node_t* createNode(int key) {
	node_t* newNode = (node_t*)malloc(sizeof(node_t));
	newNode->value = key;
	newNode->next = newNode->prev = NULL;
	return newNode;
}

void insertToList(node_t * newNode) {
	newNode->next = head;
	if (head != NULL) head->prev = newNode;
	head = newNode;
	newNode->prev = NULL;
}

void deleteNode(node_t * node) {
	if (node->prev != NULL) node->prev->next = node->next;
	if (node->next != NULL) node->next->prev = node->prev;
}

void printList() {
	node_t* current = head;
	if (current == NULL) return;
	printf("%d", current->value);
	current = current->next;
	while (current != NULL) {
		printf(" %d", current->value);
		current = current->next;
	}
	printf("\n");
}
