#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* tail){
    tail = malloc(sizeof(node));
    tail -> prev = tail;
    tail -> next = tail;
    return tail;
}

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

node* del_first(node* tail){
    node* head = tail->next;
    if(head -> next == tail){//difference between = and == !
        tail->next = tail;
        tail->prev = tail;
    }
    else{
        head -> next -> prev = tail;
        tail -> next = head -> next;
    }
    free(head);
    return tail;
}

node* del_last(node* tail){
    node* last = tail->prev;
    if(last -> prev == tail){
        tail->next = tail;
        tail->prev = tail;
    }
    else{
        tail -> prev = last -> prev;
        last -> prev -> next = tail;
    }
    free(last);
    return tail;
}

node* del_node(node* tail, int n){
    node* ptr = tail->next;
    while(ptr->key!=n){
        if(ptr==tail)
            return tail;
        ptr = ptr -> next;
    }
    if(ptr == tail -> next){
        ptr -> next -> prev = tail;
        tail -> next = ptr -> next;
    }
    else if(ptr == tail->prev){
        ptr -> prev -> next = tail;
        tail -> prev = ptr -> prev;
    }
    else{
        ptr -> prev -> next = ptr -> next;
        ptr -> next -> prev = ptr -> prev;
    }
    free(ptr);
    return tail;
}

void display(node* tail){
    node* ptr = tail -> next;
    if(ptr==tail){
        printf("\n");
        return;
    }
    while(ptr!=tail){
        if(ptr->next == tail){
            printf("%d\n", ptr->key);
            break;
        }
        printf("%d ", ptr->key);
        ptr = ptr -> next;
    }
    return;
}

int main(){

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

