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

#define N 100000

struct node {
    int key;
    struct node *next;
};
typedef struct node *NodePointer;

typedef struct{
    char ask[20];
    int key2;
}Roll;

NodePointer insert(int);
NodePointer finditem(int);
NodePointer make_1node(int, NodePointer);
NodePointer delete(int);
void deleteFirst(void);
void deleteLast(void);
void list(void);

NodePointer head;

int main() {

    int n;
    int i;
    Roll Ask[N];

    scanf("%d", &n);
	head = make_1node(0, NULL);

    for (i = 0; i < n; i++) {
	   scanf("%s", Ask[i].ask);
	   if (strcmp(Ask[i].ask, "deleteFirst") != 0)
		   scanf("%d", &Ask[i].key2);
	   else if(strcmp(Ask[i].ask, "deleteLast") != 0)
		   scanf("%d", &Ask[i].key2);

	   if (strcmp(Ask[i].ask, "insert") == 0)
		   insert(Ask[i].key2);
	   else if (strcmp(Ask[i].ask, "delete") == 0)
		   delete(Ask[i].key2);
	   else if (strcmp(Ask[i].ask, "deleteFirst") == 0)
		   deleteFirst();
	   else if (strcmp(Ask[i].ask, "deleteLast") == 0)
		   deleteLast();
}
	list();

    return 0;
}
NodePointer insert(int keydata) {
	NodePointer newnode;
	if (finditem(keydata) == NULL) {
		newnode = make_1node(keydata, head->next);
		head->next = newnode;
		return newnode;
	}
	else return NULL;
}
NodePointer finditem(int value) {
	NodePointer n;
	for (n = head; n -> next != NULL; n = n->next) {
		if (n->next->key == value) return n;
	}
	return NULL;
}
NodePointer make_1node(int keydata, NodePointer p) {
	NodePointer n;

	if ((n = (NodePointer)malloc(sizeof(struct node))) == NULL)
		exit(8);
	n->key = keydata;
	n->next = p;
	return n;
}
void list(void) {
	NodePointer n;
	for (n = head ->next; n != NULL; n = n->next)
		printf("%d ", n->key);
	printf("\n");
}
NodePointer delete(int keydata) {
	NodePointer n, delnode;
	if ((n = finditem(keydata)) != NULL) {
		delnode = n->next;
		n->next = delnode->next;
		free(delnode);
		return n;
	}
	else return NULL;
}
void deleteFirst(void) {
	NodePointer delnode;
	delnode = head->next;
	head->next = delnode->next;
	free(delnode);

}
void deleteLast(void){
	NodePointer n,delnode;
	for (n = head; n->next != NULL; n = n->next) {};
	delnode = n;
	n = n->next;
	free(delnode);

}