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

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

void init(void);
void insert(int key);
void delete(int target);
void deleteFirst(void);
void deleteLast(void);
void printList(void);

int main(void)
{
    init();

    int num_op;
    scanf("%d", &num_op);

    char op[12];
    int key;

    while (num_op--) {
        scanf("%s", op);
        if (strcmp(op, "insert") == 0) {
            scanf("%d", &key);
            insert(key);
        } else if (strcmp(op, "delete") == 0) {
            scanf("%d", &key);
            delete(key);
        } else if (strcmp(op, "deleteFirst") == 0) {
            deleteFirst();
        } else {
            deleteLast();
        }
    }

    printList();
    return 0;
}

    /*
       ------- root <------
      |                    |
       --> 3 --> 2 --> 1 --
    */

nodePtr root;
void init(void)
{
    root = malloc(sizeof(struct node));
    root->next = root;
    root->prev = root;
}

void insert(int key)
{
    nodePtr inserted;
    inserted = malloc(sizeof(struct node));
    inserted->next = root->next;
    inserted->prev = root;
    inserted->key = key;

    root->next->prev = inserted;
    root->next = inserted;
}

void deleteNode(nodePtr node);

void delete(int target)
{
    nodePtr current = root->next;
    while (current != root) {
        if (current->key == target) {
            deleteNode(current);
            return ;
        }
        current = current->next;
    }
}

void deleteNode(nodePtr node)
{
    if (node == root) {
        return ;
    }
    node->next->prev = node->prev;
    node->prev->next = node->next;
    free(node);
}

void deleteFirst(void)
{
    deleteNode(root->next);
}

void deleteLast(void)
{
    deleteNode(root->prev);
}

void printList(void)
{
    nodePtr current = root->next;
    int isFirst = 1;
    while (current != root) {
        if (isFirst == 0) {
            printf(" ");
        }
        printf("%d", current->key);
        current = current->next;
        isFirst = 0;
    }
    printf("\n");
}