// id: ALDS1_3_C
// CPU: 00:28sec  Memory: 32972KB
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

#define MAX_LEN 11

struct Node;
typedef int ElementType;
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;

struct Node {
	ElementType element;
	Position prior;
	Position next;
};

List create_list(void);
void make_empty(List l);
void delete_list(List l);
bool is_empty(List l);
void insert(List l, ElementType x);
void delete(List l, ElementType x);
Position find(List l, ElementType x);
void delete_first(List l);
void delete_last(List l);
void print_list(List l);
static void terminate(const char *message);

int main(void)
{
	int n;
	List dlist = create_list();

	scanf("%d", &n);

	for ( int i = 0; i < n; ++i ) {
		char command[MAX_LEN + 1];
		int key;

		scanf("%s", command);
		
		if ( strcmp(command, "insert") == 0 ) {
			scanf("%d", &key);
			insert(dlist, key);
		}
		else if ( strcmp(command, "delete") == 0 ) {
			scanf("%d", &key);
			delete(dlist, key);
		}
		else if ( strcmp(command, "deleteFirst") == 0 )
			delete_first(dlist);
		else
			delete_last(dlist);
	}

	print_list(dlist);

	delete_list(dlist);

	return 0;
}

List create_list(void)
{
	List l;

	l = malloc(sizeof(struct Node));
	if ( l == NULL )
		terminate("Error in create: list could not be created.");

	l->prior = l;
	l->next = l;

	return l;
}

void make_empty(List l)
{
	while ( !is_empty(l) )
		delete_first(l);
}

void delete_list(List l)
{
	make_empty(l);

	free(l);
}

bool is_empty(List l)
{
	return l->next == l;
}

void insert(List l, ElementType x)
{
	Position tmp = malloc(sizeof(struct Node));

	if ( tmp == NULL ) {
		delete_list(l);
		terminate("Error in insert: fail to allocate space for the new node.");
	}

	tmp->element = x;
	tmp->next = l->next;
	tmp->prior = l;

	l->next = tmp;
	tmp->next->prior = tmp;
}

void delete(List l, ElementType x)
{
	Position p;

	p = find(l, x);

	if ( p != NULL ) {
		p->prior->next = p->next;
		p->next->prior = p->prior;
		
		free(p);
	}
}

Position find(List l, ElementType x)
{
	Position p;

	for ( p = l->next; p != l && p->element != x; p = p->next )
		;

	if ( p == l )
		p = NULL;

	return p;
}

void delete_first(List l)
{
	Position tmp = l->next;

	if ( is_empty(l) ) {
		delete_list(l);
		terminate("Error in delete_first: list is empty.");
	}

	l->next = tmp->next;
	tmp->next->prior = l;

	free(tmp);
}

void delete_last(List l)
{
	Position tmp = l->prior;

	if ( is_empty(l) ) {
		delete_list(l);
		terminate("Error in delete_last: list is empty.");
	}

	tmp->prior->next = l;
	l->prior = tmp->prior;

	free(tmp);
}

void print_list(List l)
{
	Position p = l->next;

	if ( p != l ) {
		printf("%d", p->element);
		p = p->next;
	}

	while ( p != l ) {
		printf(" %d", p->element);
		p = p->next;
	}

	printf("\n");
}

static void terminate(const char *message)
{
	printf("%s\n", message);
	exit(EXIT_FAILURE);
}
