#include <bits/stdc++.h>
#include <cmath>

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef long long ll;
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX / 100;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
const double PI = 3.14159265358979323846;

typedef pair<string, int> P;


string to_upper(string str) {
    int diff = 'a' - 'A';
    for (int i = 0; i < str.size(); i++) {
        char c = str[i];
        if ('A' <= c && c <= 'Z') {
            c += diff;
            str[i] = c;
        }
    }
    return str;
}

struct Element {
    Element *before, *after;
    ll key;
};

class LinkedList {
    Element *begin = new Element;
    Element *end = new Element;

public:
    LinkedList() {
        begin->key = -INF;
        end->key = INF;

        begin->after = end;
        end->before = begin;
    }

    void insert(ll i) {
        Element *new_element = new Element;
        new_element->key = i;
        Element *current_top = begin->after;
        Element *head = begin;

        head->after = new_element;
        new_element->before = head;

        new_element->after = current_top;
        current_top->before = new_element;
    }

    void del(ll i) {
        Element *now = begin->after;
        rep(j, i) {
            now = now->after;
        }

        Element *bef = now->before;
        Element *af = now->after;

        bef->after = af;
        af->before = bef;

        delete now;

    }

    void print() {
        Element *now = begin;
        if (now->after == end) {
            cout << endl;
            return;
        }
        while (true) {
            now = now->after;
            cout << now->key;
            if (now->after->key == INF) {
                cout << endl;
                return;
            } else {
                cout << ' ';
            }

        }
    }

    void pop_front() {

        Element *head = begin;
        Element *current_top = begin->after;
        Element *current_second = current_top->after;

        head->after = current_second;
        current_second->before = head;

        delete current_top;

    }

    void pop_back() {

        Element *back = end;
        Element *current_back = back->before;
        Element *current_second = current_back->before;

        back->before = current_second;
        current_second->after = back;

        delete current_back;
    }

    void del_match(ll key) {
        Element *now = begin;
        while (now != NULL) {
            if (now->key == key) {
                Element *bef = now->before;
                Element *af = now->after;

                bef->after = af;
                af->before = bef;

                delete now;

                return;
            }
            now = now->after;
        }

    }

};

int main() {

//    int n, q;
//    cin >> n >> q;
    cin.tie(0); ios::sync_with_stdio(false);
    LinkedList list;

    int n;
    cin >> n;
    rep(i, n) {
        string command;
        cin >> command;
        if (command == "insert") {
            ll key;
            cin >> key;
            list.insert(key);
        } else if (command == "delete") {
            ll key;
            cin >> key;
            list.del_match(key);
        } else if (command == "deleteFirst") {
            list.pop_front();
        } else if (command == "deleteLast") {
            list.pop_back();
        }

    }

    list.print();

}



Measured memory_bytes: 34480