#include <stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node{
    long long int data;
    struct Node* next;
    struct Node* prev;
};
struct Node* list;
struct Node* end;
void insertTop(long long int data){
    struct Node* newN = (struct Node*)malloc(sizeof(struct Node));
    newN->data = data;
    newN->prev = NULL;
    newN->next = NULL;
    if(list == NULL){
        list = newN;
        end = newN;
        return;
    }
    list->prev = newN;
    newN->next = list;
    list = newN;
}
void insertBottom(long long int data){
    struct Node* newN = (struct Node*)malloc(sizeof(struct Node));
    newN->data = data;
    newN->prev = NULL;
    newN->next = NULL;
    if(end == NULL){
        list = newN;
        end = newN;
        return;
    }
    end->next = newN;
    newN->prev = end;
    end = newN;
}
void deleteX(long long int x){
    struct Node* temp = list;
    struct Node* p;
    struct Node* n;
    while(temp != NULL){
        if(temp->data == x){
            //printf("found %lld\n", x);
            //printf("next %lld\n",temp->next->data);
            p = temp->prev;
            n = temp->next;
            if(p == NULL && n == NULL) {
                list = NULL; end=NULL;break;
            }
            if(p == NULL){
                list = temp->next;
                list->prev = NULL;
            }else p->next = n;
            if(n==NULL){
                end = end->prev;
                end->next = NULL;
            }else n->prev = p;
            break;
        }
        temp = temp->next;
    }
}
void deleteTop(){
    list = list->next;
    if(list == NULL){
        end = NULL;
    }else list->prev = NULL;
}
void deleteBottom(){
    end = end->prev;
    if(end == NULL){
        list = NULL;
    }else end->next = NULL;
}
void print(){
    struct Node* temp = list;
    while(temp != NULL){
        printf("%d", temp->data);
        temp = temp->next;
        if(temp == NULL)printf("\n");
        else printf(" ");
    }
}
void tnirp(){
    struct Node* temp = end;
    if(temp == NULL)return;
    while(temp!=NULL){
        printf("%d<-", temp->data);
        temp = temp->prev;
    }
    printf("\n");
}
int main(){
    list = NULL;
    struct Node* temp;
    char cmd[13];
    long long int n, x;
    scanf("%lld", &n);
    while(n--){
        scanf("%s", &cmd);
        if(strcmp(cmd, "deleteFirst")== 0){
            deleteTop();
        }else if(strcmp(cmd, "deleteLast") == 0){
            deleteBottom();
        }else if(strcmp(cmd, "insert") == 0){
            scanf("%lld", &x);
            insertTop(x);
        }else if(strcmp(cmd, "delete") == 0){
            scanf("%lld", &x);
            deleteX(x);
        }
    }
    print();

    return 0;
}

