#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LMAX 1000000

struct node{
    int key;
    struct node *next;
};
typedef struct node * NodePointer;

NodePointer head;

NodePointer make_1node(int,NodePointer);//ノード作成
void listprint();//ノード表示
NodePointer finditem(int);//ノード内検索
void insert(int);//ノード追加
void delete(int);//ノード削除
void deletefirst();//先頭ノード削除
void deletelast();


int main(){
    int n;
    int x;
    int count = 0;
    char c[15];

    head = make_1node(0,NULL);

    scanf("%d",&n);
    count = n;

    for(int i = 0;i < n;i++){
        scanf("%s",c);
        if(strcmp("insert",c) == 0){
            scanf("%d",&x);
            insert(x);
        }
        else if(strcmp("deleteFirst",c) == 0)deletefirst();
        else if(strcmp("deleteLast",c) == 0)deletelast();
        else {
            scanf("%d",&x);
            delete(x);
        }
    }

    listprint();

    return 0;
}

NodePointer make_1node(int keydata,NodePointer P){
    NodePointer n;

    if((n = (NodePointer)malloc(sizeof(struct node))) == NULL){
        printf("Error in memory allocation\n");
        exit(8);
    }
    n->key = keydata;
    n->next = P;

    return n;
}

void listprint(){
    NodePointer n;

    for(n = head->next;n != NULL;n = n->next){
        printf("%d",n->key);
        if(n->next != NULL)printf(" ");
    }
    printf("\n");
}

NodePointer finditem(int value){
    NodePointer n;

    for(n = head;n->next != NULL;n = n->next)if(n->next->key == value)return n;
    return NULL;
}

void insert(int keydata){
    NodePointer newnode;

    newnode = make_1node(keydata,head->next);
    head->next = newnode;
}

void delete(int keydata){
    NodePointer n,delnode;

    if((n = finditem(keydata)) != NULL){
        delnode = n->next;
        n->next = delnode->next;
        free(delnode);
    }
}

void deletefirst(){
    NodePointer n,delnode;

    delnode = head->next;
    n = delnode->next;
    head->next = n;
    free(delnode);
}

void deletelast(){
    NodePointer n,delnode;

    for(n = head->next;n->next->next != NULL;n = n->next){};
    delnode = n->next;
    n->next = delnode->next;
    free(delnode);
}
