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

/***** 双方向連結リスト *****/
struct node{
        int v;
        struct node *prev;
        struct node *next;
};

void insert(struct node *n, int num){
        struct node *x = (struct node*)malloc(sizeof(struct node));
        x->v = num;
        x->prev = n;
        x->next = n->next;
        if(n->next != NULL){
                n->next->prev = x;
        }
        n->next = x;
}

void delete(struct node *n){
        if(n->prev != NULL){
                n->prev->next = n->next;
        }
        if(n->next != NULL){
                n->next->prev = n->prev;
        }
        free(n);
}

void release(struct node *head){
        struct node *x = head->next;
        while(x != NULL){
                struct node* del = x;
                x = x->next;
                free(del);
        }
        head->next = NULL;
}
int main(void){
        int i, N, num;
        char d[12];

        struct node head;
        head.prev = NULL;
        head.next = NULL;
        scanf("%d", &N);
        for(i=0; i<N; i++){
                scanf("%s", d);
                if(strcmp("insert", d) == 0){
                        scanf("%d", &num);
                        insert(&head, num);
                }else if(strcmp("delete", d) == 0){
                        scanf("%d", &num);
                        struct node* x = &head;
                        while(1){
                                if(x->v == num) break;
                                x = x->next;
                        }
                        delete(x);
                }else if(strcmp("deleteFirst", d) == 0){
                        delete(head.next);
                }else if(strcmp("deleteLast", d) == 0){
                        struct node* x = &head;
                        while(1){
                                if(x->next == NULL) break;
                                x = x->next;
                        }
                        delete(x);
                }else if(strcmp("deleteAll", d) == 0){
                        release(&head);
                }else{
                        printf("error direction\n");
                }
        }

        struct node *p = head.next;
        while(p->next != NULL){
                printf("%d ", p->v);
                p = p->next;
        }
        printf("%d\n", p->v);
        release(&head);

        return 0;
}
