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

struct node{
	int key;
	struct node *next;
	struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

void init()
{
	nil = NULL;
}

void insert(int key)
{
	struct node *newcell;

	newcell = (struct node*)malloc(sizeof(struct node));
	if (newcell == NULL) {
		puts( "malloc failed." );
		return;
	}

	if (nil == NULL) {
		nil = newcell;
		nil->next = nil;
		nil->prev = nil;
		nil->key = key;
		return;
	} else if (nil->next == nil) {
		nil->prev = newcell;
	} else if (nil->next->next == nil) {
		nil->prev->prev = newcell;
	}
	newcell->key = nil->key; 
	newcell->prev = nil;
	newcell->next = nil->next;
	nil->next->prev = newcell;
	nil->next = newcell;
	nil->key = key;
	return;
}

void deleteLast()
{
	struct node *last;
	if (nil->next == nil) {
		free(nil);
		nil = NULL;
		return;
	} else {
		last = nil->prev;
		nil->prev->prev->next = nil;
		nil->prev = last->prev;
		free(last);
	}
}

void deleteFirst()
{
	struct node *first;
	if (nil->prev == nil) {
		free(nil);
		nil = NULL;
		return;
	} else {
		first = nil;
		nil = nil->next;
		nil->prev = first->prev;
		first->prev->next = nil;
		free(first);
	}
}

void _delete(int key)
{
	struct node *p;
	if (nil->key == key) {
		deleteFirst();
		return;
	}
	for (p = nil->next; p != nil; p = p->next) {
		if (p->key == key) {
			p->prev->next = p->next;
			p->next->prev = p->prev;
			free(p);
			return;
		}
	}
}

void printList()
{
	struct node *p;
	printf("%d", nil->key);
	for (p = nil->next; p != nil; p = p->next) {
		printf(" %d", p->key);
	}
	printf("\n");
	return;
}

int main(){
	int i, n, key;
	char com[12];
	struct node *p;

	scanf("%d", &n);
	init();

	for ( i = 0; i < n; i++ ){
		scanf("%s", com);

		if ( com[0] == 'i' ) {
			scanf("%d", &key);
			insert(key);
		} else if ( com[0] == 'd' ) {
			if (strlen(com) > 6){
				if ( com[6] == 'F' ) {
					deleteFirst();
				} else if ( com[6] == 'L' ) {
					deleteLast();
				}
			} else {
				scanf("%d", &key);
				_delete(key);
			}
		}
	}
	printList();
	return 0;
}