/* 
 * File:   main.c
 * Author: Ivan
 *
 * Created on June 25, 2018, 7:45 PM
 */

#include <cstdio>
#include <cstdlib>

struct Item {
    int key;
    Item *next, *prev;
};
//typedef struct{
//    int key;
//    Item *next;
//    Item *prev;
//}Item;

Item *null;

Item *search(int key);

void print();

void deleteItem(Item *m);

void deleteKey(int key);

void insert(int key);

/*
 * 
 */

//int main(int argc, char** argv) {
int main() {
    int key, n, np = 0, nd = 0, size = 0;
    char command[50];
    
    scanf("%d", &n);
    
    null = (Item *)malloc(sizeof(Item));
    null->next = null;
    null->prev = null;
    
    for (int i = 0; i < n; ++i)
    {
        scanf("%s%d", command, &key);
        if (command == "insert") { insert(key); np++; size++; }
        else if ( command == "deleteFirst") { deleteItem(null->next); size--; }
        else if ( command == "deleteLast") { deleteItem(null->prev); size--; }
        else { deleteKey(key); size--; }
    }
    
    print();
    
    return (EXIT_SUCCESS);
}

Item* search(int key)
{
    Item *current = null->next;
    while ( current != null && current->key != key)
    {
        current = current->next;
    }
    return current;
}

void print()
{
    Item *current = null->next;
    printf("%d", current->key);
    while (1)
    {
        if (current == null) break;
        printf(" ");
        printf("%d", current->key);
        current = current->next;
    }
    printf("\n");
}

void deleteItem(Item *m)
{
    if (m == null) return;
    m->prev->next = m->next;
    m->next->prev = m->prev;
    free(m);
}

void deleteKey(int key)
{
    deleteItem(search(key));
}

void insert(int key)
{
    Item *x = (Item *)malloc(sizeof(Item));
    x->key = key;
    x->next = null->next;
    null->next->prev = x;
    null->next = x;
    x->prev = null;
}

