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

struct node {
  struct node *p;
  int k;
  struct node *n;
};

typedef struct node *NodePointer;

void insert(int);
void delete(NodePointer);
void listprint(void);
NodePointer make_1node(int, NodePointer,NodePointer);

NodePointer head;
NodePointer tail;

int list_count=0;

int main() {
    NodePointer n;
    char command[12];
    int count,num,time=0,flag=0;
    char command_list[4][12]={{"insert"},{"delete"},{"deleteFirst"},{"deleteLast"}};
    head = make_1node(0,NULL,NULL);
    tail = make_1node(0,head,NULL);
    head->n = tail;
    
    scanf("%d",&count);
    while(count>0){
        count--;
        scanf("%s",command);

        if(strcmp(command,command_list[0]) == 0) { 
            scanf("%d",&num);
            insert(num);
            list_count++;
        }

        else if(strcmp(command,command_list[1]) == 0) {
            scanf("%d",&num);
            for(n =head->n; n != tail; n=n->n){
                if(n->k == num){
                    n->p->n = n->n;
                    n->n->p = n->p;
                    delete(n);
                    break;
                }
            }
        }
            
        else if(strcmp(command,command_list[2]) == 0) { 
            n = head->n;
            head->n = n->n;
            head->n->p = head;
            delete(n);
        }
            
        else if(strcmp(command,command_list[3]) == 0) {
	  n=tail->p;
	  tail->p = n->p;
            tail->p->n = tail;
            delete(n);
        }
        
    }
    for(n=head->n; n != tail->p; n=n->n)printf("%d ",n->k);
    printf("%d\n",n->k);
  
    return 0;
}

void insert(int num) {
    NodePointer newnode = make_1node(num, head, head->n);
    head->n->p = newnode;
    head->n = newnode;
}

NodePointer make_1node(int num, NodePointer pre,NodePointer nex) {
    NodePointer n;

    if ((n = (NodePointer)malloc(sizeof(struct node))) == NULL) {
    printf("Error in memory allocation\n");
    exit(8);
    }
    
    n->k = num;
    n->n = nex;
    n->p = pre;
    return n;
}

void delete(NodePointer n) {
    list_count--;
    free(n);
}

