#include<bits/stdc++.h>

#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
#define FIX <<fixed<<setprecision(10)<<
using namespace std;

using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;

const ll MOD = 1e9+7;

class Stack{
private:
int m[1000];
int tp;
public:
    Stack(){
    tp=0;
    }
    void push(int x){
        tp++;
        m[tp]=x;
    }
    int pop(){
        tp--;
        return m[tp+1];
    }
}; 
class Queue{
private:
pair<string,int> m[60000];
int head,tail;
public:
    Queue(){
        head=0;
        tail=0;
    }
    bool isEmpty(){
        return head==tail;
    }
    void enqueue(pair<string,int> x){
        m[tail]=x;
        if(tail +1 ==60000)tail=0;
        else tail++;
    }
    pair<string,int> deque(){
        pair<string,int> x=m[head];
        if(head+1==60000)head=0;
        else head++;
        return x;
    } 
};

struct Node{
    int key;
    Node* prev;
    Node* next;
};

class LinkedList{
public:
LinkedList(){
    dammy= new Node();
    dammy->key =-1;
    dammy->prev= dammy;
    dammy->next= dammy;
}
~LinkedList(){
    Node* tmpNode =dammy->next;
    Node* nextNode;
    while(tmpNode != dammy){
        nextNode=tmpNode->next;
        delete tmpNode;
        tmpNode=nextNode;
    }
    delete dammy;
}
void insertNode(int x){
    Node* tmpNode=dammy->next;
    dammy->next=new Node();
    dammy->next-> key =x;
    dammy->next->next=tmpNode;
    dammy->next->prev=dammy;
    tmpNode->prev = dammy->next;
}
    void deleteNode(int x){
        Node* tmpNode = dammy->next;
        while(tmpNode != dammy && tmpNode->key != x){
            tmpNode = tmpNode->next;
        }
        if(tmpNode != dammy){  
            tmpNode->prev->next = tmpNode->next;
            tmpNode->next->prev = tmpNode->prev;
            delete tmpNode;
        }
    }
    void deleteFirst(){
        Node* tmpNode = dammy->next;
        dammy->next = dammy->next->next;
        dammy->next->prev = dammy;
        delete tmpNode; 
    };
 
    void deleteLast(){
        Node* tmpNode = dammy->prev;
        dammy->prev = dammy->prev->prev;
        dammy->prev->next = dammy;
        delete tmpNode; 
    };

    void printList(){
    Node* currentNode = dammy->next;;
    int sp = 1;
    while(1){
    if ( currentNode == dammy ) break;
    if ( sp == 0)  cout<<" ";
    cout<<currentNode->key;
    currentNode = currentNode->next;
    sp = 0;
    }
    cout<<endl;
    }
    private:
    Node* dammy;
};

int main(){
    int n;
    cin>>n;
    string command;
    int number;
    LinkedList L1;
    REP(i,n){
    cin>>command;
    if(command=="insert"){
        cin>>number;
        L1.insertNode(number);
    }else 
    if(command=="delete"){
        cin>>number;
        L1.deleteNode(number);
    }else 
    if(command=="deleteFirst")L1.deleteFirst();
    else if(command=="deleteLast")L1.deleteLast();
    }
    L1.printList();
    }


Measured memory_bytes: 34424