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

typedef struct node *link;
struct node {
	int item;
	link next;
	link back;
};

void printlist(link h) {
	link t;
	for (t = h; t != NULL; t = t->next) {
		printf("%d", t->item);
		if (t->next != NULL) printf(" ");
	}
	printf("\n");
}


int main(void) {
	int n, i, d;
	link t, head = NULL;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		char comm[20];
		scanf("%s", comm);
		if (strlen(comm) < 7) scanf("%d", &d);

		if (comm[0] == 'i') {
			//printf("Command[%d] is insert %d => ", i + 1, d);
			link new = malloc(sizeof(link));
			new->item = d;
			new->next = head;
			if (head == NULL) new->back = new;
			else {
				new->back = head->back;
				head->back = new;
			}
			head = new;
		}
		else if (comm[0] == 'd') {
			if (comm[6] == 'F' || (strlen(comm) < 7 && head->item == d)) {
				if (head->next == NULL) {
					free(head);
					head = NULL;
				}
				else {
					t = head;
					head = head->next;
					head->back = t->back;
					free(t);
				}
			}
			else if (comm[6] == 'L') {
				if (head->back == head) {
					free(head);
					head = NULL;
				}
				else {
					t = head->back;
					head->back = t->back;
					t->back->next = NULL;
					free(t);
				}
			}
			else {
				link prev;
				t = head;
				while (t->item != d && t->next != NULL) {
					prev = t;
					t = t->next;
				}
				if (t->item == d) {
					prev->next = t->next;
					if (t->next == NULL) t->next = head;
					t->next->back = prev;
					free(t);
				}
			}
		}
	}

	printlist(head);

	return 0;
}