#define MAX 1000000

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

//?§???????.
typedef struct command {
	char txt[12];
	int x;
}com;

//????????????????????£?¨?.
void ins(int x);
void del(int x);
void delF(void);
void delL(void);

//??°?????????????????°.
int head = 0;
int tail = 0;
int num[MAX];


int main(void) {
	int n = 0;		//????????°.
	com buf;		//????????????.
	int i = 0;
	int k = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s", buf.txt);		//?????????????????????.
		
		if (strcmp(buf.txt, "insert") == 0) {
			scanf("%d", &buf.x);
			ins(buf.x);
		}
		else if (strcmp(buf.txt, "delete") == 0) {
			scanf("%d", &buf.x);
			del(buf.x);
		}
		else if (strcmp(buf.txt, "deleteFirst") == 0) {
			delF();
		}
		else if (strcmp(buf.txt, "deleteLast") == 0) {
			delL();
		}

		//???????????°.
		for (k = head - 1; k >= tail; k--) {
			if (k != tail)
				printf("%d ", num[k]);
			else
				printf("%d\n", num[k]);
		}
	}

	for (i = head - 1; i >= tail; i--) {
		if (i != tail)
			printf("%d ", num[i]);
		else
			printf("%d\n", num[i]);
	}

	return 0;
}

void ins(int x) {
	num[head] = x;
	head++;
}

void del(int x) {
	int i = 0;
	int v[2] = {};

	v[1] = num[head - 1];

	for (i = head - 1; i >= tail; i--) {
		v[0] = num[i];
		num[i] = v[1];

		if (v[0] == x)
			break;
		else {
			v[1] = v[0];
		}
	}

	head--;
}

void delF(void) {
	num[head - 1] = 0;
	head--;
}

void delL(void) {
	num[tail] = 0;
	tail++;
}