#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <sstream>
using namespace std;

#define MAX 100

//Doubly Linked List
struct Node{
  long long int data;
  Node* next;
  Node* prev;
};

class DLList{
    private: 
        Node *first;
        Node *last;
        int length;
    public:
        DLList(){
            first = NULL;
            last = NULL;
            length = 0;
        }
        void insertId(int index, int data){
            Node *currentNode;
            Node *beforeNode;
            Node *newNode = new Node;
            newNode->data = data;
            newNode->prev = NULL;
            newNode->next = NULL;
            currentNode = first;
            if(first == NULL){
                first = newNode;
                last = newNode;
            }else{
                for(int i=0; i<index; i++){
                    beforeNode = currentNode;
                    currentNode = currentNode->next;
                }
                if(index == 0){
                    newNode->next = currentNode;
                    currentNode->prev = newNode;
                    first = newNode;
                }else if(index == length){
                    newNode->prev = beforeNode;
                    beforeNode->next = newNode;
                    last = newNode;
                }else{
                    beforeNode->next = newNode;
                    newNode ->prev = beforeNode;
                    newNode->next = currentNode;
                    currentNode->prev = newNode;
                    //cout << "check3 " << endl;
                }
            }
            length++;
        }
        void deleteId(int index){
            Node *currentNode;
            Node *beforeNode;
            currentNode = first;
            for(int i=0; i<index; i++){
                beforeNode = currentNode;
                currentNode = currentNode->next;
            }
            if(index == 0){
                first = currentNode->next;
                currentNode->prev = NULL;
            }else if(index == length){
                last = beforeNode;
                beforeNode->next = NULL;
            }else{
                beforeNode->next = currentNode->next;
                if(currentNode->next != NULL){
                    currentNode->next->prev = beforeNode;
                }
            }
            length--;
        }
        void deleteKey(int key){
            Node *currentNode;
            Node *beforeNode;
            currentNode = first;
            if(length == 1){
                if(currentNode->data == key){
                    first = NULL;
                    last = NULL;
                    length--;
                }
            }else{
                for(int i=0; i< length ; i++){
                    if(currentNode->data == key){
                        if(i == 0){
                            first = currentNode->next;
                            if(currentNode->next != NULL){
                                currentNode->next->prev = NULL;
                            }
                        }else if(i == length-1){
                            last = beforeNode;
                            beforeNode->next = NULL;
                        }else{
                            beforeNode->next = currentNode->next;
                            if(currentNode->next != NULL){
                                currentNode->next->prev = beforeNode;
                            }
                        }
                        length--;
                        break;
                    }
                    beforeNode = currentNode;
                    currentNode = currentNode->next;
                }
            }
        }
        void deleteFirst(){
            if(length == 1){
                first = NULL;
                last = NULL;
            }
            else{
                if(first->next != NULL){
                    first->next->prev = NULL;
                }
                first = first->next;
            }
            length--;
        }
        void deleteLast(){
            if(length == 1){
                first = NULL;
                last = NULL;
            }
            else{
                if(last->prev != NULL){
                    last->prev->next = NULL;
                }
                last = last->prev;
            }
            length--;
        }
        long long int getId(int index){
            Node *currentNode;
            currentNode = first;
            for(int i=0; i<index; i++){
                currentNode = currentNode->next;
            }
            return currentNode->data;
        }
        int getLength(){
            return length;
        }
        void printList(){
            Node *currentNode;
            currentNode = first;
            for(int i=0; i<length; i++){
                cout << currentNode->data;
                currentNode = currentNode->next;
                if(currentNode == NULL){
                    cout << endl;
                    break;
                }else{
                    cout << " ";
                }
            }
            /*cout << "frist:" << first->data << " last:" << last->data <<endl;
            if(last->prev != NULL){
            cout << "last_prev:"<<last->prev->data << endl;
            }*/
        }
};

int main()
{
    DLList dllist1;
    string op;
    int N;
    long long int num;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> op;
        if(op == "insert"){
            cin >> num;
            //cout << op <<" "<< num << endl;
            dllist1.insertId(0, num);
        }else if(op == "delete"){
            cin >> num;
            //cout << op << "" << num << endl;
            dllist1.deleteKey(num);
        }else if(op == "deleteFirst"){
            //cout << op << endl;
            dllist1.deleteFirst();
        }else if(op == "deleteLast"){
            //cout << op << endl;
            dllist1.deleteLast();
        }
    }
    dllist1.printList();
    return 0;
}


Measured memory_bytes: 37544