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


typedef struct node *link;
struct node {
    int item;
    link next;
    link prev;
};

void printList(link);

int main(void) {
    int n, i = 0, data;
    link head = NULL, last = NULL, t;
    char command[12];
    scanf("%d", &n);
    while (i < n) {
        scanf("%s", command);
        if (!strcmp(command, "insert")) {
            scanf("%d", &data);
            t = malloc(sizeof(*t));
            t->item = data;
            t->next = head;
            if (t->next != NULL) t->next->prev = t;
            t->prev = NULL;
            head = t;
            if (t->next == NULL) last = t;
        } else if (!strcmp(command, "delete")) {
            scanf("%d", &data);
            t = head;
            while (t != NULL) {
                if (t->item == data) {
                    if (t->prev != NULL) t->prev->next = t->next;
                    else head = t->next;
                    if (t->next != NULL) t->next->prev = t->prev;
                    else last = t->prev;
                    free(t);
                    break;
                } else t = t->next;
            }
        } else if (!strcmp(command, "deleteFirst")) {
            t = head;
            if (head == last) last = NULL;
            head = head->next;
            if (t->next != NULL) t->next->prev = NULL;
            free(t);
        } else if (!strcmp(command, "deleteLast")) {
            t = last;
            if (last == head) head = NULL;
            last = last->prev;
            if (t->prev != NULL)t->prev->next = NULL;
            free(t);
        } else printf("Invalid Command.\n");
        i++;
    }
    printList(head);
    return 0;
}

void printList(link l) {
    link t = l;
    while (t->next != NULL) {
        printf("%d ", t->item);
        t = t->next;
    }
    if (t != NULL) printf("%d\n", t->item);
}