#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct node{
        int data;
        struct node *next;
        struct node *prev;
}llist;
llist *head = NULL;
llist *last = NULL;
void insert(int);
void delete(int);
void deleteFirst(void);
void deleteLast(void);
main()
{
        int n, key;
        char command[12];
        llist *p;
        scanf("%d", &n);
        while(n--){
                scanf("%*c%s", command);
                if(!strcmp(command, "insert")){
                        scanf(" %d", &key);
                        insert(key);
                }else if(!strcmp(command, "delete")){
                        scanf(" %d", &key);
                        delete(key);
                }else if(!strcmp(command, "deleteFirst")){
                        deleteFirst();
                }else if(!strcmp(command, "deleteLast")){
                        deleteLast();
                }
        }
        if(head != NULL){
                printf("%d", head -> data);
                p = head -> next;
                while(p != NULL){
                        printf(" %d", p -> data);
                        p = p -> next;
                }
                putchar('\n');
        }
}
void insert(int data)
{
        llist *p;
        if((p = (llist*)malloc(sizeof(llist))) == NULL){
                fprintf(stderr, "Memory cannot allocate\n");
                exit(0);
        }
        p -> data = data;
        p -> prev = NULL;
        p -> next = head;
        head = p;
        if(last == NULL){
                last = p;
        }else{
                        p -> next -> prev = p;
                }
}
void delete(int data)
{
        llist *p = head;
        while(p != NULL){
                if(p -> data == data){
                        if(p != head){
                                p -> prev -> next = p -> next;
                        }else{
                                head = p -> next;
                        }
                        if(p != last){
                                p -> next -> prev = p -> prev;
                        }else{
                                last = p -> prev;
                        }
                        free(p);
                        return;
                }
                p = p -> next;
        }
}
void deleteFirst(void)
{
        llist *p = head;
        if(last == NULL){
                        return;
        }
        if(head -> next == NULL){
                        last = NULL;
        }else{
                        head -> next -> prev = NULL;
        }
                head = head -> next;
                free(p);
        return;
}
void deleteLast(void)
{
        llist *p = last;
    if(head == NULL){
        return;
    }
    if(last -> prev == NULL){
        head = NULL;
    }else{
        last -> prev -> next = NULL;
    }
    last = last -> prev;
    free(p);
    return;
}