#include <string.h> 
#include <stdio.h> 
#include <stdlib.h>
#define max 50000000
struct N { 
    int K; 
    struct N *P, *N; 
}; 
 
struct N *nale; 
int k,ccc=0;
void l_ini();
void l_ins();
struct N* list_S(int );
void D_N(struct N *);
void D_F();
void D_L();
void D_K(int );
void print_L();
  


int main(void) { 
  int K, n, i; 
    int size = 0; 
    char com[20],comcomcom[max]; 
    int np = 0, nd = 0; 
    scanf("%d", &n); 
    l_ini(); 
    for (i = 0; i < n; i++) { 
        scanf("%s%d",com, &K); 
        if(com[0] == 'i') { 
            l_ins(K); 
            np ++; 
            size++; 
        }else if(com[0] == 'd') { 
            if(strlen(com) > 6) { 
                if( com[6] == 'F') { 
                    D_F(); 
                }else if(com[6] == 'L') { 
                    D_L(); 
                } 
            }else { 
                D_K(K); 
                nd ++; 
            } 
            size --; 
        }
	for(k=0;k<max;k++){ccc++;}
    } 
    print_L(); 
    return 0; 
} 




void l_ini() { 
    nale = (struct N *)malloc(sizeof(struct N)); 
    nale->N = nale; 
    nale->P = nale;for(k=0;k<max;k++){ccc++;}
    
} 
 
void l_ins(int K) { 
    struct N * xmen = (struct node *)malloc(sizeof(struct N)); 
    xmen->K = K; 
    xmen->N = nale->N; 
    nale->N->P = xmen; 
    nale->N = xmen; 
    xmen->P = nale; for(k=0;k<max;k++){ccc++;}
} 
 
struct N* list_S(int K) { 
    struct N *cur = nale->N; 
    while(cur != nale && cur->K != K ) { 
        cur = cur-> N; for(k=0;k<max;k++){ccc++;}
    } 
    return cur; 
} 
 
void D_N(struct N *t) { 
    if (t == nale) return; 
    t->P->N = t->N; 
    t->N->P = t->P; for(k=0;k<max;k++){ccc++;}
    free(t); 
} 
 
void D_F() { 
    D_N(nale->N);for(k=0;k<max;k++){ccc++;} 
} 
 
void D_L() { 
    D_N(nale->P); for(k=0;k<max;k++){ccc++;}
} 
void D_K(int K) { 
    D_N(list_S(K)); for(k=0;k<max;k++){ccc++;}
} 

void print_L() { 
    struct N *cur; 
    cur = nale->N; 
    int isf = 0; 

    while(1) { 
        if (cur == nale) break; 
        if(isf++ > 0) printf(" "); 
        printf("%d", cur->K); 
        cur = cur->N; for(k=0;k<max;k++){ccc++;}
    } 
    printf("\n"); 
}  

