#include <stdio.h>
#include <vector>
#include <array>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <stdexcept>
#include <functional>


#include <string.h>

using std::string;
using std::vector;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// util
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

std::vector<std::string> split(const std::string& input, char delimiter = ' ')
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// user func
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// definition

// リストの中身
class Node{
private:
    Node* prevPtr;
    Node* nextPtr;
    int value;
public:
    Node(int value, Node* prevPtr, Node* nextPtr)
        : value(value)
        , prevPtr(prevPtr)
        , nextPtr(nextPtr)
    {
    }

    int Value(){
        return this->value;
    }

    Node* Prev(){
        return this->prevPtr;
    }    
    void Prev(Node* pointer){
        this->prevPtr = pointer;
    }

    Node* Next() const {
        return this->nextPtr;
    };

    void Next(Node* pointer){
        this->nextPtr = pointer;
    }

    bool HasNext(){
        return this->nextPtr != nullptr;
    }
};

// リストの実装
class LinkedList{
private:
    Node* front;
    Node* end;
public:
    const int NullIndex = -1;
    LinkedList()
        : front(new Node(0, nullptr, nullptr))
        , end(new Node(0, nullptr, nullptr))
    {
        this->front->Next(this->end);
        this->end->Prev(this->front);
    }
    ~LinkedList(){
        this->traverse([](Node* node){
            delete node;
            return true;
        });
    }

    // only insert to first
    void Insert(int data){
        Node* node = new Node(data, this->front, this->front->Next());
        // Next の previous
        this->front->Next()->Prev(node);
        // front の next
        this->front->Next(node);
    }

    void Delete(int data){
        this->traverse([data, this](Node* node){
            if (node->Value() == data) {
                node->Prev()->Next(node->Next());
                node->Next()->Prev(node->Prev());
                delete node;
                return false;
            }
            return true;
        });
    }

    void DeleteFirst(){
        auto next = this->front->Next();
        auto newNext = next->Next();
        delete next;
        this->front->Next(newNext);
        newNext->Prev(this->front);
    }

    void DeleteLast(){
        auto prev = this->end->Prev();
        auto newPrev = prev->Prev();
        delete prev;
        this->end->Prev(newPrev);
        newPrev->Next(this->end);
    }

    void traverse(std::function<bool(Node*)> fn){
        Node* current = this->front->Next();
        while(current->HasNext()){
            auto next = current->Next();
            bool done = !fn(current);
            current = next;
            if (done) break;
        }
    }

    void print() {
        this->traverse([](Node* node){
            printf("%d", node->Value());
            if(node->Next()->HasNext()) printf(" ");
            return true;
        });
        printf("\n");
    }
};

void solve() {

    int n = 0;
    scanf("%d\n", &n);

    LinkedList list;
    for(int i = 0; i < n; i++){
        char command[128];
        int value;
        scanf("%s %d", command, &value);
        if(strcmp("deleteFirst", command) == 0){
            list.DeleteFirst();
            continue;
        }
        if(strcmp("deleteLast", command) == 0){
            list.DeleteLast();
            continue;
        }

        if (strcmp(command, "insert") == 0){
            list.Insert(value);
            continue;
        } 
        if(strcmp(command, "delete") == 0){
            list.Delete(value);
            continue;
        }
    }

    list.print();

}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// main
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    
    solve();
    return 0;
}


Measured memory_bytes: 34352