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

typedef struct _node {
    int x;
    struct _node *prev;
    struct _node *next;
} Node;

typedef struct {
    Node *head;
} List;

Node *alloc() {
    return malloc(sizeof(Node));
}

void set(Node *ptr, int x, Node *prev, Node *next) {
    ptr->x = x;
    ptr->prev = prev;
    ptr->next = next;
}

bool initList(List *list) {
    if((list->head = alloc()) == NULL) {
        return false;
    }

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

bool isEmptyList(List *list) {
    return list->head->next == list->head;
}

bool insertAfter(Node *ptr, int x) {
    Node *new = alloc();
    
    if(new == NULL) {
        return false;
    }

    Node *next = ptr->next;

    ptr->next = next->prev = new;
    set(new, x, ptr, next);

    return true;
}

bool insertFront(List *list, int x) {
    return insertAfter(list->head, x);
}

bool insertRear(List *list, int x) {
    return insertAfter(list->head->prev, x);
}

Node *search(List *list, int x) {
    Node *ptr = list->head->next;

    while(ptr != list->head) {
        if(ptr->x == x) {
            return ptr;
        }
        ptr = ptr->next;
    }

    return NULL;
}

void _remove(Node *ptr) {
    Node *prev = ptr->prev;
    Node *next = ptr->next;

    prev->next = next;
    next->prev = prev;
    free(ptr);
}

bool removeFront(List *list) {
    if(isEmptyList(list)) {
        return false;
    }

    _remove(list->head->next);
    
    return true;
}

bool removeRear(List *list) {
    if(isEmptyList(list)) {
        return false;
    }

    _remove(list->head->prev);
    
    return true;
}

bool removeX(List *list, int x) {
    if(isEmptyList(list)) {
        return false;
    }

    Node *ptr = search(list, x);
    if(ptr == NULL) {
        return false;
    } else {
        _remove(ptr);
        return true;
    }
}

void printList(List *list) {
    Node *ptr = list->head->next;

    while(ptr != list->head) {
        printf("%d", ptr->x);
        ptr = ptr->next;
        if(ptr == list->head) {
            break;
        }
        printf(" ");
    }

    puts("");
}

void terminateList(List *list) {
    while(!isEmptyList(list)) {
        removeFront(list);
    }
}

int main(void) {
    List list;
    char buf[32];
    int n;

    initList(&list);

    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d", &n);

    for(int i = 0; i < n; i++) {
        fgets(buf, sizeof(buf), stdin);
        char command[16];
        int x;
        sscanf(buf, "%s %d", command, &x);
        if(!strcmp(command, "insert")) {
            insertFront(&list, x);
        } else if(!strcmp(command, "delete")) {
            removeX(&list, x);
        } else if(!strcmp(command, "deleteFirst")) {
            removeFront(&list);
        } else if(!strcmp(command, "deleteLast")) {
            removeRear(&list);
        }
    }

    printList(&list);

    terminateList(&list);

    return 0;
}
