#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

using namespace std;
struct Node {
    Node *prev;
    Node *next;
    int key;
};

void insertFirst(Node** first, int key) {

}

void deleteNode(Node** first, int key) {

}

void deleteFirst(Node** first) {

}

void deleteLast(Node** last) {

}

Node* makeNode(int key, Node *prev, Node *next) {
    Node* node = new Node();
    node->key = key;
    node->next = next;
    node->prev = prev;
    return node;
}

void printNode(Node *firstNode, Node* lastNode) {
    for (Node *node = firstNode; node != nullptr; node = node->next)
    {
        if (node != firstNode)
        {
            cout << " ";
        }
        cout << node->key;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    Node* firstNode = nullptr;
    Node* lastNode = nullptr;
    for(int i=0; i<n; i++) {
        char command[20];
        int x;
        scanf("%s", &command);
        if(!strcmp(command, "insert")) {
            scanf("%d", &x);
            Node* newFirstNode = makeNode(x, nullptr, firstNode);
            if(firstNode) {
                newFirstNode->next->prev = newFirstNode;
            }else {
                lastNode = newFirstNode;
            }
            firstNode = newFirstNode;
            //printNode(firstNode, lastNode);
        }else if(!strcmp(command, "delete")) {
            scanf("%d", &x);
            for (Node *node = firstNode; node != nullptr; node = node->next){
                if(node->key != x) continue;
                
                if(node->prev && node->next) {
                    node->prev->next = node->next;
                    node->next->prev = node->prev;
                    break;
                }else if(node->prev == nullptr && node->next) {
                    firstNode = node->next;
                    node->next->prev = nullptr;
                    break;
                }else if(node->prev && node->next == nullptr) {
                    lastNode = node->prev;
                    node->prev->next = nullptr;
                    break;
                }else {
                    firstNode = nullptr;
                    lastNode = nullptr;
                    break;
                }
                
            }
            //printNode(firstNode, lastNode);
        }else if(!strcmp(command, "deleteFirst")) {
            if(firstNode->next) {
                firstNode->next->prev = nullptr;
            } else {
                lastNode = nullptr;
            }
            firstNode = firstNode->next;
            //printNode(firstNode, lastNode);
        }else if(!strcmp(command, "deleteLast")) {
            if(lastNode->prev) {
                lastNode->prev->next = nullptr;
            } else {
                firstNode = nullptr;
            }
            lastNode = lastNode->prev;
            //printNode(firstNode, lastNode);
        }
    }
    printNode(firstNode, lastNode);
}


Measured memory_bytes: 37476