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

typedef struct node list;

struct node {
    int key;
    list *next;
    list *prev;
};

list *head, *tail;

void insert(int key) {
    int i;
    list *new;
    new = (list*)malloc(sizeof(list));
    new->key = key;
    new->next = head->next;
    new->prev = head;
    head->next = new;

    if (new->next == NULL) tail = new;
}

void del(int key) {
    list *t = head->next, *prev = head;
    while(t != NULL && t->key != key) {
        prev = t;
        t = t->next;
    }

    if (t != NULL) {
        prev->next = t->next;
        if (t->next != NULL) t->next->prev = prev;
        else tail = prev;
        free(t);
    }
}

void del_first() {
    list *first = head->next;
    head->next = first->next;
    if (first->next != NULL) first->next->prev = head;
    else tail = head;
    free(first);
}

void del_last() {
    list *last = tail;
    tail = tail->prev;
    tail->next = NULL;
    free(last);
}

void show() {
    list *t = head->next;
    while(t != NULL) {
        printf("%d%c", t->key, ((t->next == NULL) ? '\n' : ' '));
        t = t->next;
    }
}

int main() {
    int n;
    char command[10];
    int key;
    int i;

    scanf("%d", &n);
    head = (list*)malloc(sizeof(list));
    head->key = -1;
    head->next = NULL;
    tail = head;
    for(i = 0; i < n; i++) {
        scanf("%s", command);

        if (strcmp(command, "insert") == 0) {
            scanf("%d", &key);
            insert(key);
        } else if (strcmp(command, "delete") == 0) {
            scanf("%d", &key);
            del(key);
        } else if (strcmp(command, "deleteFirst") == 0) {
            del_first();
        } else if (strcmp(command, "deleteLast") == 0) {
            del_last();
        }
        show();
    }

    show();
    return 0;
}