#include <iostream>
#include <string>
#include <cstdio>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)

using namespace std;

template <typename T>
struct Node{
    T value_;
    Node* prev_;
    Node* next_;

    Node(){
        prev_ = next_ = this;
    }
    Node(T value,Node* prev ,Node* next){
        value_ = value;
        prev_ = prev;
        next_ = next;
    }
};

template <typename T>
class DoublyLinkedList{
    private:
        //ダミーノード
        Node<T> *head_;
        //Current Node
        Node<T> *cur_;

    public:
        DoublyLinkedList(){
            //ダミーノード生成
            head_ = cur_ = new Node<T>();
        }

        ~DoublyLinkedList(){
            clear();
        }

        bool empty(){
            return head_ -> next_ == head_;
        }

        T find (T &value){
            //初期ポインタ
            Node<T> *ptr = head_ -> next_;
            while(ptr != head_){
                if(ptr -> value_ == value){
                    cur_ = ptr;
                    return ptr -> value_;
                }
                ptr = ptr -> next_;
            }

            return nullptr;
        }

        int find(int value){
            //初期ポインタ
            Node<T> *ptr = head_ -> next_;
            while(ptr != head_){
                if(ptr -> value_ == value){
                    cur_ = ptr;
                    return ptr -> value_;
                }
                ptr = ptr -> next_;
            }

            return -1;
        }

        void findFirstptr(T &value){
            Node<T> *ptr = head_ -> next_;
            while(ptr != head_){
                if(ptr -> value_ == value){
                    cur_ = ptr;
                    return;
                }
                ptr = ptr -> next_;
            }
            cur_ = ptr;
        }

        void printCurrentNode(){
            if(empty()){
                cout << "This list is empty" << endl;
            }else{
                cout << cur_ -> value_ << endl;
            }
        }

        void printAllNode(){
            Node<T> *ptr = head_ -> next_;
            while(ptr != head_){
                if (ptr -> prev_ == head_){
                    cout << ptr -> value_;
                }else{
                    cout << " " << ptr -> value_;
                }
                ptr = ptr -> next_;
            }
            cout << endl;
        }

        void printAllNodeInt(){
            Node<int> *ptr = head_ -> next_;
            while(ptr != head_){
                if (ptr -> prev_ == head_){
                    printf("%d", ptr -> value_);
                }else{
                    printf(" %d", ptr -> value_);
                }
                ptr = ptr -> next_;
            }
            printf("\n");
        }
        /*
        void printAllReverse(){
            Node<T> *ptr = head_ -> prev_;

            while(ptr != head_){
                cout << ptr -> value_ << " ";
                ptr = ptr -> prev_;
            }
            cout << endl;
        }
        */

        bool next(){
            if(empty() or cur_ -> next_ == head_){
                return false;
            }
            cur_ = cur_ -> next_;
            return true;
        }
        bool prev(){
            if(empty() or cur_ -> prev_ == head_){
                return false;
            }
            cur_ = cur_ -> prev_;
            return true;
        }

        void insert(T value){
            //今回はcurrent nodeの次に挿入する
            //node<T> (値、前、後)になっている。
            Node<T> *node = new Node<T>(value,cur_ , cur_ -> next_);

            //連結
            cur_ -> next_ = cur_ -> next_ -> prev_ = node;

            //カレントポインタに設定
            cur_ = node;
        }

        void push_front(T value){
            cur_ = head_;
            insert(value);
        }

        void push_back(T value){
            cur_ = head_ -> prev_;
            insert(value);
        }

        void eraseCurrentNode(){
            if(!empty()){
                //繋ぎ変えてメモリの開放
                cur_ -> prev_ -> next_ = cur_ -> next_;
                cur_ -> next_ -> prev_ = cur_ -> prev_;
                delete cur_;

                //currentNodeは消した前に設定する
                cur_ = cur_ -> prev_;
            }
        }

        void pop_front(){
            cur_ = head_ -> next_;
            eraseCurrentNode();
        }

        void pop_back(){
            cur_ = head_ -> prev_;
            eraseCurrentNode();
        }

        void clear(){
            while(!empty()){
                pop_front();
            }
        }

        void eraseSpecificNode(T value){
            findFirstptr(value);
            if(cur_ != head_){
                eraseCurrentNode();
            }
        }
};

int main(){
    int n; cin >> n;
    DoublyLinkedList<int> lists;    

    rep(i,n){
        string s;
        cin >> s;

        if(s[0] == 'i'){
            int x; scanf("%d" , &x);
            lists.push_front(x);
        }else{
            switch(s.length()){
                case 6:
                    int x; scanf("%d" , &x);
                    lists.eraseSpecificNode(x);
                    break;
                
                case 10:
                    lists.pop_back();
                    break;
                case 11:
                    lists.pop_front();
                    break;

                default:
                    cout << "Error Occured" << endl;
            }
        }
    }

    lists.printAllNode();
    
}


Measured memory_bytes: 34452