#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <sstream>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

// const ll LL_INF = 1LL<<60;

template <class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}
template <class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}

using namespace std;

template<class T> struct Node {
    Node<T>* prev_ptr;
    Node<T>* next_ptr;
    T data;

    Node(Node<T>* x=0, Node<T>* y=0, T z=-1) {
        prev_ptr = x;
        next_ptr = y;
        data = z;
    }
    inline void change(Node<T>* x, Node<T>* y, T z) {
        prev_ptr = x;
        next_ptr = y;
        data = z;
    }
};

template<class T> class DoubleLinkedList {
    Node<T> dummyNode;

public:
    DoubleLinkedList() {
        dummyNode.change(&dummyNode, &dummyNode, -1);
    }
    ~DoubleLinkedList() {
        Node<T>* tmp = dummyNode.next_ptr;
        while(tmp->data != dummyNode.data) {
            Node<T>* next = tmp->next_ptr;
            delete tmp;
            tmp = next;
        }
    }

    inline void insert(T x) {
        Node<T>* first = dummyNode.next_ptr;
        Node<T>* newNode = new Node<T>(&dummyNode, first, x);
        first->prev_ptr = newNode;
        dummyNode.next_ptr = newNode;
    }

    inline void deletes(T x) {
        Node<T>* tmp = dummyNode.next_ptr;
        while(tmp->data != dummyNode.data) {
            if (tmp->data != x) {
                tmp = tmp->next_ptr;
            } else {
                (tmp->next_ptr)->prev_ptr = tmp->prev_ptr;
                (tmp->prev_ptr)->next_ptr = tmp->next_ptr;
                delete tmp;
                break;
            }
        }
    }
    inline void deleteFirst() {
        if ((dummyNode.next_ptr)->data != dummyNode.data) {
            Node<T>* tmp = dummyNode.next_ptr;
            dummyNode.next_ptr = tmp->next_ptr;
            (tmp->next_ptr)->prev_ptr = &dummyNode;
            delete tmp;
        }
    }
    inline void deleteLast() {
        if ((dummyNode.next_ptr)->data != dummyNode.data) {
            Node<T>* tmp = dummyNode.prev_ptr;
            dummyNode.prev_ptr = tmp->prev_ptr;
            (tmp->prev_ptr)->next_ptr = &dummyNode;
            delete tmp;
        }
    }

    inline void print() {
        Node<T>* tmp = dummyNode.next_ptr;

        if (tmp->data != dummyNode.data) {
            printf("%d", tmp->data);
            tmp = tmp->next_ptr;
            while(tmp->data != dummyNode.data) {
                printf(" %d", tmp->data);
                tmp = tmp->next_ptr;
            }
        }
        printf("\n");
    }
};

int main() {
    DoubleLinkedList<int> list;
    int n;
    scanf("%d\n", &n);
    rep(i, n) {
        char str[30];
        scanf("%s", str);
        if (str[6] == 'F') {
            list.deleteFirst();
        } else if (str[6] == 'L') {
            list.deleteLast();
        } else if (str[0] == 'i') {
            int x;
            scanf("%d", &x);
            list.insert(x);
        } else {
            int x;
            scanf("%d", &x);
            list.deletes(x);
        } 
    }
    list.print();
}



Measured memory_bytes: 34404