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

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

Node *head = NULL;
Node *tail = NULL;

void insert(int val){
    Node* p_head = head;
    //??°???node?????????
    Node* node = malloc(sizeof(Node));
    node->val = val;
    node->next = p_head;
    node->prev = NULL;
    //??????????????\
    head = node;
    if(p_head != NULL){
        p_head->prev = node;
    }
    //?????????????´??????´??????tail????¨??????????
    if(tail==NULL){
        tail = node;
    }
}

void delete(int val){
    Node* c_node = head;
    //????´???°???0??§????????°???????????????
    if(head == NULL) return;
    //???????????????????????¢?????????
    while(c_node != NULL && c_node->val != val){
        c_node = c_node->next;
    }
    if(c_node == NULL) return;
    
    //????´???°???1?????´???
    if(head->next == NULL){
        head = NULL;
        tail = NULL;
    }
    //????´????1????????§?????????????????????????±????head?????´???
    else if(c_node == head)
    {
        head = c_node->next;
        head->prev = NULL;
    }
    //????´????1????????§?????????????????????????±????tail?????´???
    else if(c_node == tail)
    {
        tail = c_node->prev;
        tail->next = NULL;
    }
    else
    {
        c_node->prev->next = c_node->next;
        c_node->next->prev = c_node->prev;
    }
    free(c_node);
}

void deleteFirst(void){
    Node* p_head = head;
    //????´???°???0??§????????°???????????????
    if(head == NULL) return;
    
    //????´???°???2??\????????´???
    if(head->next != NULL)
    {
        head = head->next;
        head->prev = NULL;
    }
    else
    //????´???°???1?????´???
    {
        head = NULL;
        tail = NULL;
    }
    free(p_head);
}

void deleteLast(void){
    Node* p_tail = tail;
    //????´???°???0??§????????°???????????????
    if(tail == NULL) return;
    
    //????´???°???2??\????????´???
    if(tail->prev != NULL)
    {
        tail = tail->prev;
        tail->next = NULL;
    }
    //????´???°???1?????´???
    else
    {
        head = NULL;
        tail = NULL;
    }
    free(p_tail);
}

void printAll(void){
    Node* node = head;
    if(node == NULL) return;
    while(node != NULL){
        printf("%d", node->val);
        node = node->next;
        if(node != NULL) printf(" ");
    }
    printf("\n");
}

int main(void){
    int i;
    int num;
    char operator[20];
    int operand;
    
    scanf("%d", &num);
    
    for(i=0;i<num;i++){
        scanf("%s", operator);
        if(strcmp(operator, "insert") == 0){
            scanf("%d", &operand);
            insert(operand);
        }
        else if(strcmp(operator, "delete") == 0){
            scanf("%d", &operand);
            delete(operand);
        }
        else if(strcmp(operator, "deleteFirst") == 0){
            deleteFirst();
        }
        else if(strcmp(operator, "deleteLast") == 0){
            deleteLast();
        }
    }
    printAll();
    return 0;
}