#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
using namespace std;

template<class T>
class LinearList
{
public:
    LinearList()
    {}
    ~LinearList()
    {}

};


template<class T>
struct DblNode
{
    T data;
    DblNode<T> *lLink, *rLink;
    DblNode(DblNode<T> *left = NULL, DblNode<T> *right = NULL)
        :lLink(left), rLink(right)
    {}
    DblNode(T value, DblNode<T> *left = NULL, DblNode<T> *right = NULL)
        :data(value), lLink(left), rLink(right)
    {}
    friend ostream &operator << (ostream &os, DblNode<T> &node)
    {
        os << node.data;
        return os;
    }
};

template<class T>
class DblList:public LinearList<T>
{
public:
    DblList(T uniqueVal);
    ~DblList()
    {}
    int Length() const;
    bool IsEmpty() {return first->rlink == first;}
    DblNode<T> *getHead() const {return first;}
    void setHead(DblNode<T> *ptr) {first = ptr;}

    DblNode<T> *Search(const T &x);
    DblNode<T> *Locate(int i, int d);
    bool Insert(int i, T &x, int d);

    bool InsertFront(const T &x);
    bool Delete(const T &x);
    bool RemoveFirst();
    bool RemoveLast();

    bool Remove(int i, T &x, int d);
    void Print();

private:
    DblNode<T> *first;

};

template<class T>
DblList<T>::DblList(T uniqueVal)
{
    first = new DblNode<T>(uniqueVal);
    if (first == NULL)
    {
        cerr << "memory error!!!" << endl;
       // exit(1);
    }
    first->rLink = first->lLink = first;
}

template<class T>
int DblList<T>::Length() const
{
    DblList<T> *current = first->rLink;
    int count = 0;
    while (current != first)
    {
        current = current->rLink;
        count++;
    }
}

template<class T>
DblNode<T> *DblList<T>::Search(const T &x)
{
    DblNode<T> *current = first->rLink;
    while (current != first && current->data != x)
    {
        current = current->rLink;
    }
    if (current != first)
    {
        return current;
    }
    else
    {
        return NULL;
    }
}

template<class T>
bool DblList<T>::Delete(const T &x)
{
    DblNode<T> *current = Search(x);
    if (current != NULL)
    {
        current->lLink->rLink = current->rLink;
        current->rLink->lLink = current->lLink;
        return true;
    }
    else
    {
        return false;
    }

}

template<class T>
bool DblList<T>::InsertFront(const T &x)
{
    DblNode<T> *newNode = new DblNode<T>(x);
    if (newNode == NULL)
    {
        cerr << "memory error" << endl;
        //exit(0);
    }
    newNode->lLink = first;
    newNode->rLink = first->rLink;
    first->rLink = newNode;
    newNode->rLink->lLink = newNode;

    return true;
}

template<class T>
bool DblList<T>::RemoveFirst()
{
    if (first->rLink != first)
    {
        first->rLink = first->rLink->rLink;
        first->rLink->lLink = first;
    }
    return true;
}

template<class T>
bool DblList<T>::RemoveLast()
{
    if (first->lLink != first)
    {
        first->lLink = first->lLink->lLink;
        first->lLink->rLink = first;
    }

    return true;
}

template<class T>
void DblList<T>::Print()
{
    DblNode<T> * current = first->rLink;
    DblNode<T> cur = *current;
    if (current != first)
    {
        cout << cur;
    }
    current = current->rLink;
    cur = *current;
    while (current != first)
    {
        cout << " " << cur ;
        current = current->rLink;
        cur = *current;

    }
    printf("\n");
}

int main()
{
    char *str = (char*)malloc(20 * sizeof(char));
    DblList<int> dlist(-100);

    int n, num;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%s", str);
        if (strcmp(str, "insert") == 0)
        {
            scanf("%d", &num);
            dlist.InsertFront(num);
        }
        else if (strcmp(str, "delete") == 0)
        {
            scanf("%d", &num);
            dlist.Delete(num);
        }
        else if (strcmp(str, "deleteFirst") == 0)
        {
            dlist.RemoveFirst();
        }
        else if (strcmp(str, "deleteLast") == 0)
        {
            dlist.RemoveLast();
        }
    }
    dlist.Print();
    return 0;
}



Measured memory_bytes: 37524