#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
typedef struct Node {
    struct Node *next;
    struct Node *prev;
    long key;
} NODE;
 
NODE *front = NULL;
NODE *rear = NULL;
 
void insert(long key)
{
    NODE *node = (NODE *)malloc(sizeof(NODE));
    node->prev = NULL;
    node->next = NULL;
    node->key = key;
    if (front == NULL) {
        front = rear = node;
    }
    else {
       front->prev = node;
       node->next = front;
       front = node;
    }
}
 
void delete_first()
{
    NODE *tmp = front;
    if (tmp != NULL) {
        if (front == rear) {
	    front = NULL;
	    rear = NULL;
	}
	else {
	    front = tmp->next;
	    front->prev = NULL;
	}
	free(tmp);
    }
}
 
void delete_last()
{
    NODE *tmp = rear;
    if (tmp != NULL) {
        if (front == rear) {
	    front = NULL;
	    rear = NULL;
        }
        else {
	    rear = tmp->prev;
	    rear->next = NULL;
        }
	free(tmp);
    }
}
 
void delete(long key)
{
    NODE *node = front;
    while (node != NULL) {
        if (node->key == key) {
            if (node == front) {
                delete_first();
            }
            else if (node == rear) {
                delete_last();
            }
            else {
                node->next->prev = node->prev;
                node->prev->next = node->next;
                free(node);
		node = NULL;
            }
            break;
        }
	node = node->next;
    }
}
 
int main(int argc, int *argv[])
{
    int i, num;
    char cmd[16];
    long key;
     
    scanf("%d", &num);
 
    for(i = 0; i < num; i++) {
        scanf("%s", cmd);
 
        if (strcmp(cmd, "insert") == 0) {
            scanf("%ld", &key);
            insert(key);
        }
        else if (strcmp(cmd, "delete") == 0) {
            scanf("%ld", &key);
            delete(key);
        }
        else if (strcmp(cmd, "deleteFirst") == 0) {
            delete_first();
        }
        else if (strcmp(cmd, "deleteLast") == 0) {
            delete_last();
        }
    }
 
    NODE *node = front;
    while (node != NULL) { 
	if (node == rear) {
            printf("%ld\n", node->key);
        }
        else {
            printf("%ld ", node->key);
        }

        NODE *tmp = node->next;
	free(node);
	node = tmp;
    }
    return 0;
}