// Doubly Linked List
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

Node* head;

Node* listSearch(int key){
    Node* node = head->next;
    while(node != head && node->key != key){
        node = node->next;
    }
    return node;
}

void init(){
    if((head = (Node*)malloc(sizeof(Node))) == NULL){
        puts("error");
        return;
    }
    head->next = head;
    head->prev = head;
}

void printList(){
    Node* current = head->next;
    int isf = 1;
    while(1){
        if(current == head)break;
        if(isf == 0)printf(" ");
        printf("%d", current->key);
        current = current->next;
        isf = 0;
    }
    puts("");
}

void deleteNode(Node* t){
    if(t == head)return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(head->next);
}

void deleteLast(){
    deleteNode(head->prev);
}

void delete(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node* x;
    if((x = (Node*)malloc(sizeof(Node))) == NULL){
        puts("error");
        return;
    }
    x->key = key;
    x->next = head->next;
    head->next->prev = x;
    head->next = x;
    x->prev = head;
}
 
int main(void){
    int key, n, i;
    char command[20];
    scanf("%d", &n);
    init();
    for(i=0; i<n; i++){
        scanf("%s%d", command, &key);
        if(command[0] == 'i'){
            insert(key);   
        }else if(command[0] == 'd'){
            if(strlen(command) > 6){
                if(command[6] == 'F')deleteFirst();
                else if(command[6] == 'L')deleteLast();
            }else{
                delete(key);
            }
        }
    }
    printList();
    return 0;
}
