#define _CRT_SECURE_NO_WARNINGS
////#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
typedef struct LIST{
	struct LIST *next;
	struct LIST *prev;
	int value;
}NODE,*PNODE;

PNODE list;
void Add(int);
void Del(int);
void DelFirst();
void DelLast();
void DelNode(PNODE);
void Display();
void Release();

int main() {
	list = (NODE*)malloc(sizeof(NODE));
	list->next = list;
	list->prev = list;
	int fig,n,f;
	char op[13];
	fscanf(stdin, "%d", &n),getchar();
	while (n--) {
		fscanf(stdin, "%[^\n]*s", op),getchar();
		f == 0;
		if (op[0] == 'i') { f = 1; }
		else if (op[0] == 'd') {
			switch (op[6]) {
			case 'F':
				DelFirst();
				break;
			case 'L':
				DelLast();
				break;
			default:
				f = 2;
				break;
			}
		}
		if (f) {
			fig = atoi(&op[7]);
			if (f == 1) Add(fig);
			else if (f == 2) Del(fig);
		}
	}
	Display();
	Release();
	return 0;
}

void Add(int tmp){
	NODE *p, *next, *prev;
	p = (NODE*)malloc(sizeof(NODE));
	p->value = tmp;
	p->next = list->next;
	p->prev = list;
	list->next->prev = p;
	list->next = p;
}

void Del(int tmp){
	PNODE cur = list->next;
	while (cur != list) {
		if (cur->value == tmp) {
			DelNode(cur);
			return;
		}
		cur = cur->next;
	}
}

void DelFirst(){
	DelNode(list->next);
}

void DelLast(){
	DelNode(list->prev);
}

void DelNode(PNODE node){
	if (node == list) return;
	node->next->prev = node->prev;
	node->prev->next = node->next;
}

void Display() {
	if (list->next == list) { puts("list is empty"); return; }
	NODE *p= list->next;
	fprintf(stdout, "%d", p->value);
	p = p->next;
	for (; p != list; p = p->next) fprintf(stdout, " %d", p->value);
	puts("");
}

void Release(){
	NODE *next, *del;
	next = list->next;
	while (next != list){
		del = next;
		next = next->next;
		free(del);
	}
}