#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

struct Node;

struct Node
{
    Node(int n)
    : value(n), next((Node*)nullptr), prev((Node*)nullptr)
    {}

    int value;
    Node* next;
    Node* prev;
};

template <typename T, typename KEY>
class myDoublyLinkedList
{
public:
    myDoublyLinkedList()
    : first((T*)nullptr)
    {}

    ~myDoublyLinkedList() {}

    void insert(KEY x)
    {
        T* node = new T{x};
        if (first)
        {
            T* last = first->prev;
            node->next = first;
            node->prev = last;
            first->prev = node;
            last->next = node;
            first = node;
        }
        else
        {
            first = node;
            node->next = node;
            node->prev = node;
        }
    }

    void del(KEY x)
    {
        T* it;
        for (it = first; it != first->prev && it->value != x; it = it->next);

        if (it->value == x)
        {
            if (it == first) deleteFirst();
            else if (it == first->prev) deleteLast();
            else
            {
                if (it->prev == it)
                {
                    first = (T*)nullptr;
                    delete it;
                }
                else
                {
                    it->next->prev = it->prev;
                    it->prev->next = it->next;
                    delete it;
                }
            }
        }
    }

    void deleteFirst()
    {
        T* temp = first;
        if (first->prev == first)
        {
            first = (T*)nullptr;
        }
        else
        {
            first->next->prev = first->prev;
            first->prev->next = first->next;
            first = first->next;
        }

        delete temp;
    }

    void deleteLast()
    {
        T* last = first->prev;
        if (last == first)
        {
            first = (T*)nullptr;
        }
        else
        {
            last->prev->next = first;
            first->prev = last->prev;
        }

        delete last;
    }

    void print()
    {
        for (T* it = first; it != first->prev; it = it->next)
        {
            cout << it->value << " ";
        }
        cout << first->prev->value << "\n";
    }

private:
    T* first;
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    char command[32];
    int key;
    myDoublyLinkedList<Node, int> dl;

    cin >> n;
    rep (i, n)
    {
        cin >> command;
        if (strcmp(command, "insert") == 0)
        {
            cin >> key;
            dl.insert(key);
        }
        else if (strcmp(command, "delete") == 0)
        {
            cin >> key;
            dl.del(key);
        }
        else if (strcmp(command, "deleteFirst") == 0)
        {
            dl.deleteFirst();
        }
        else if (strcmp(command, "deleteLast") == 0)
        {
            dl.deleteLast();
        }
        else
        {
            return 1;
        }
    }

    dl.print();

    return 0;
}



Measured memory_bytes: 34276