#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

void printM(vector<vector<long> > &vec, long height, long width){
    F(i, 0, height){
        F(j, 0, width){
            cout << vec[i][j] << space;
        }
        cout << endl;
    }
}

class List {
    public:
    List* next;
    List* back;
    int key;

    List(List* next,List* back, int key){
        this->next = next;
        this->back = back;
        this->key = key;
    }
};

class DoubleList {
    List* head;
    List* last;

    public:

    DoubleList(){
        head = nullptr;
        last = nullptr;
    }

    void printAll(){
        List *tmp = head;
        while(tmp!=nullptr){
            if(tmp->next ==nullptr){
                cout << tmp->key;
            }else
                cout << tmp->key << space;
            tmp = tmp->next;
        }
        cout << endl;
    }

    int operator [](int index){
        List* tmp = head;
        while(index >0){
            if(tmp==nullptr)break;
            tmp = tmp->next;
            index--;
        }
        if(tmp==nullptr){
            return 0;
        }
        return tmp->key;
    }

    void insert(int x){
        List* list = new List(head,nullptr, x);
        if(head != nullptr)
            this->head->back = list;
        else
            this->last = list;
        this->head = list;
    }

    void deleteElement(int x){
        List* tmp = this->head;
        while(tmp != nullptr){
            // delete tmp is key is x
            if(tmp->key == x){
                if(tmp->back != nullptr)
                    tmp->back->next = tmp->next;
                else
                    // tmp is head
                    head = tmp->next;

                if(tmp->next != nullptr)
                    tmp->next->back = tmp->back;
                else
                   // tmp is last 
                   last = tmp->back;
                delete tmp;
                break;
            }
            tmp = tmp->next;
        }
    }

    void deleteFirst(){
        if(head == nullptr)return;
        List* tmp = this->head->next;
        if(tmp != nullptr)
            tmp->back = nullptr;
        else
            last = nullptr;
        delete head;
        this->head = tmp;
    }

    void deleteLast(){
        List* tmp = last;
        if(tmp->back != nullptr)
            tmp->back->next = nullptr;
        else
            // tmp is head
            head = nullptr;
        last = tmp->back;
        delete tmp;
    }
};

#define TST 0
int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n;
    DoubleList dlist;
    string op;
    int x;
    cin >> n;
    F(i, 0, n){
        cin >> op;
        if(op=="insert"){
            cin >> x;
            dlist.insert(x);
        }else if(op == "delete"){
            cin >> x;
            dlist.deleteElement(x);
        }else if(op == "deleteFirst"){
            dlist.deleteFirst();
        }else if(op == "deleteLast"){
            dlist.deleteLast();
        }
        //dlist.printAll();
    }
    dlist.printAll();



#if TST==1

#endif
}



Measured memory_bytes: 34408