#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

typedef struct Node * NodePointer;
NodePointer head;

NodePointer listSearch(int);
void init();
void printList();
void deleteNode(NodePointer);
void deleteFirst();
void deleteLast();
void deleteKey(int);
void insert(int);

int main(){
    int temp, size;
    char tempS[12];
    int np = 0, nd = 0;
    scanf("%d", &size);
    init();
    for(int i = 0; i < size; i++){
        scanf("%s",tempS);
        if(!strcmp(tempS,"deleteLast"))
            deleteLast();
        else if(!strcmp(tempS,"deleteFirst"))
            deleteFirst();
        else{
            scanf("%d", &temp);
            if(!strcmp(tempS,"delete"))
                deleteKey(temp);
            else if(!strcmp(tempS,"insert")) 
                insert(temp);
        }
    }
    
    printList();
    
    return (EXIT_SUCCESS);
}


NodePointer listSearch(int key){
    NodePointer loc = head->next;
    while( loc != head && loc->key != key ){
        loc = loc->next;
    }
    return loc;
}

void init(){
    head = malloc(sizeof(struct Node));
    head->next = head;
    head->prev = head;
}

void printList(){
    struct Node *cur;
    cur = head->next;
    int isf = 0;

    while(1) {
        if (cur == head) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}
    
void deleteNode(struct Node *temp) {
    if (temp == head) return;
    temp->prev->next = temp->next;
    temp->next->prev = temp->prev;
    free(temp);
}

void deleteFirst() {
    deleteNode(head->next);
}

void deleteLast() {
    deleteNode(head->prev);
}
void deleteKey(int val) {
    deleteNode(listSearch(val));
}

void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct Node));
  x->key = key;
  x->next = head->next;
  head->next->prev = x;
  head->next = x;
  x->prev = head;
}

