#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list{
    struct list *prev;
    int x;
    struct list *next;
}List;

List *insert(List *head, int x)
{
    if (head == NULL){
        List *node = (List*)malloc(sizeof(List));
        node->x = x;
        node->prev = node; 
        node->next = node;
        head = node;
    }
    else {
        List *node = (List*)malloc(sizeof(List));
        node->next = head;
        node->x = x;
        node->prev = head->prev;//last
        head->prev->next = node;//last->next
        head->prev = node;//source head prev
        head = node;
    }
    return head;
}

List * deleteFirst(List *head){
    List * tmp = head;
    head = head->next;//move head
    tmp->prev->next = head;//last to head
    head->prev = tmp->prev;//head to last
    free(tmp);
    return head;
}

void deleteLast(List *head){
    List * tmp = head->prev;
    tmp->prev->next = head;
    head->prev = tmp->prev;
    free(tmp);
}

List * delete(List *head, int x){
    //考虑 空 一个 两个 删除头节点(?) 等情况
    List *tmp;
    if (head == NULL)
        return NULL;
    List *ptr = head;
    if (head->x == x){
        head = deleteFirst(head);
        return head;
    }
    if (head->prev->x == x){
        deleteLast(head);
        return head;
    }
    do {
        if (ptr->x == x){
            tmp = ptr;
            ptr = ptr->next;
            tmp->prev->next = ptr;
            ptr->prev = tmp->prev;
            free(tmp);
        }
        else{
            ptr = ptr->next;
        }
    }
    while (ptr->next != head);
    return head;
}

void printList(List *head){
    List *ptr = head;
    do{
        if (head == ptr)
            printf("%d", ptr->x);
        else
            printf(" %d", ptr->x);
        ptr = ptr->next;
    }while(ptr != head);
    putchar('\n');
}

int main(){
    int n, num;
    char s[10];
    List *head = NULL;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%s", &s);
        if (strcmp(s, "deleteFirst") == 0){
            head = deleteFirst(head);
            continue;
        }
        if (strcmp(s, "deleteLast") == 0){
            deleteLast(head);
            continue;
        }
        scanf("%d", &num);
        if (strcmp(s, "insert") == 0)
            head = insert(head, num);
        if (strcmp(s, "delete") == 0)
            head = delete(head, num);
    }
    printList(head);
    return 0;
}
