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

typedef struct _node{
    struct _node *prev; 
    int key;
    struct _node *next;
}node;

node* init_dll(node* head, int n){
    head = malloc(sizeof(node));
    head -> prev = NULL;
    head -> key = n;
    head -> next = NULL;
    return head;
}

node* insert_beg(node* head, int n){
    node* new_node = malloc(sizeof(node));
    head -> prev = new_node;
    new_node -> prev = NULL;
    new_node -> key = n;
    new_node -> next = head;
    head = new_node;
    return head;
}

node* del_first(node* head){
    node* ptr = head;
    head = head -> next;
    head -> prev = NULL;
    free(ptr);
    return head;//important!!
}

node* del_last(node* head){
    node* ptr = head;
    while(ptr->next != NULL)
        ptr = ptr -> next;
    ptr -> prev -> next = NULL;
    free(ptr);
    return head;//important!!
}

node* del_node(node *head, int n){
    node* ptr = head;

    while(ptr->key != n)
        ptr = ptr -> next;
    if(ptr == head){
        head = head -> next;
        head -> prev = NULL;
    }
    else if(ptr -> next == NULL){
        ptr -> prev -> next = NULL;
    }
    else{
        ptr->prev->next = ptr->next;
        ptr->next->prev = ptr->prev;
    }
    free(ptr);
    return head;
}

void display(node* head){
    node* ptr = head;
    while(ptr){
        if(ptr->next == NULL){
            printf("%d\n", ptr->key);
        }
        else{
            printf("%d",ptr->key);
            printf(" ");
        }
        ptr = ptr -> next;
    }
}

int main(){

    int op_num;
    scanf("%d", &op_num);
    node* head = NULL;
    while(op_num--){
        char instr[20];
        int data;
        scanf("%s", instr);
        if(strcmp(instr,"insert")==0){
            scanf("%d", &data);
            if(head == NULL){
                head = init_dll(head, data);
            }
            else{
                head = insert_beg(head, data);
            }
        }
        else if(strcmp(instr,"delete")==0){
            scanf("%d", &data);
            head = del_node(head, data);
        }
        else if(strcmp(instr,"deleteFirst")==0){
            head = del_first(head);
        }
        else if(strcmp(instr,"deleteLast")==0){
            head = del_last(head);
        }
    }
    display(head);
}

