#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct Node {
    int num; //??°???
    struct Node *prev;
    struct Node *next;
};

struct Node *note;

void insert(int num) {
    struct Node *x = (struct Node *)malloc(sizeof(struct Node));
    x->num = num;
    note->next->prev = x;
    x->next = note->next;
    note->next = x;
    x->prev = note;
}

struct Node* search(int num) {
    struct Node *x = note->next;
    while(x != note && x->num != num ) {
        x = x-> next;
    }
    return x;
}

void deleteNode(struct Node *t) {
    if (t == note) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
}


int main(void) {
    int num, n;
    char command[20];
    scanf("%d", &n);
    note = (struct Node *)malloc(sizeof(struct Node));
    note->next = note;
    note->prev = note;
    for (int i = 0; i < n; i++) {
        scanf("%s%d",command, &num);
        if(command[0] == 'i') { //insert?????´???
            insert(num);
        }else if(command[0] == 'd') { //delete?????´???
            if(strlen(command) > 6) {
                if(strlen(command) > 10) {
                    deleteNode(note->next); //deleteFirst
                }else if(strlen(command) > 9) {
                    deleteNode(note->prev); //deleteLast
                }
            }else {
                deleteNode(search(num)); //delete
            }
        }
    }
    struct Node *x;
    x = note->next;
    int i = 0;
    while(1) {
        if (x == note) break;
        if(i++ > 0) printf(" ");
        printf("%d", x->num);
        x = x->next;
    }
    printf("\n");
    return 0;
}