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

struct node{
    int num;
    struct node *next,*prev;
};

typedef struct node * NodePointer;
NodePointer head;

void init();/*番兵ノード作成*/
NodePointer listSearch(int);/*一致するデータがあるか検索*/
void printList();/*連結リストに含まれるデータの出力*/
void deleteNode(NodePointer);/*ノードを削除*/
void deleteKey(int);/*与えられた値をリスト削除*/
void deleteFirst();/*リストの最初にある値を削除*/
void deleteLast();/*リストの最後にある値を削除*/
void insert(int);/*データを挿入*/
       
int main(){
    int n,key;
    char order[20];
    char ins[] = "insert";
    char del[] = "delete";
    char delF[] = "deleteFirst";
    char delL[] = "deleteLast";

    init();
    scanf("%d",&n);

    for(int i=0; i<n; i++){
        scanf("%s",order);
        if(strcmp(del,order) == 0 || strcmp(ins,order) == 0)scanf("%d",&key);

        if(strcmp(ins,order) == 0){
            insert(key);
        }
        else if(strcmp(del,order) == 0){
            deleteKey(key);
        }
        else if(strcmp(delF,order) == 0){
            deleteFirst();
        }
        else if(strcmp(delL,order) == 0){
            deleteLast();
        }
    }

    printList();

    return 0;
}


void init(){
    head = (NodePointer)malloc(sizeof(struct node));
    head->next = head;
    head->prev = head;
}

NodePointer listSearch(int key){
    NodePointer check;
    for(check = head->next; check != head; check = check->next){
        if(check->num == key) return check;
    }

    return NULL;
}

void printList(){
    NodePointer now = head->next;
    int dif=0;
    while(1){
        if(now == head) break;
        if(dif != 0) printf(" ");
        printf("%d",now->num);
        now = now->next;
        dif = 1; 
    }

    printf("\n");
}

void deleteNode(NodePointer key){
    if(key == head ) return;
    key->prev->next = key->next;
    key->next->prev = key->prev;
    free(key);
}

void deleteKey(int key){
    NodePointer v;
    v = listSearch(key);
    if(v == NULL) return;
    deleteNode(v);
}

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

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

void insert(int key){
    NodePointer x;
    x = (NodePointer )malloc(sizeof(struct node));
    x->num = key;

    x->next = head->next;
    head->next->prev = x;
    head->next = x;
    x->prev = head;
}

