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


/*-----------構造体定義-----------------*/
typedef struct node{
 int num;
 struct node *left;
 struct node *right;
}node;
/*--------------------------------------*/


/*-----------------要素作成-------------*/
node* makenode(int x){
node* new;

new=(node*)malloc(sizeof(node));
new->num=x;
new->right=NULL;

return new;
}
/*-------------------------------------*/


int main(){
int n,i,x;
int y=1;
char com[13];
node* root;
node* last;
node* p;
node** q;
node* r;
root=NULL;
last=NULL;
scanf("%d",&n);

for(i=0;i<n;i++){
 scanf("%s",&com);

 if(com[0]=='i'){
   scanf("%d",&x);
   p=makenode(x);
    if(root!=NULL){
        root->left=p;
        p->right=root;
        root=p;
    }else{root=p;last=p;}
 }else
 if(strcmp(com,"deleteFirst")==0){
   if(root->right==NULL){free(root);root=NULL;last=NULL;}
   else{root->right->left=NULL;
        root=root->right;}
  }else
  if(strcmp(com,"deleteLast")==0){
   if(last->left==NULL){free(root);root=NULL;last=NULL;}
   else{
    last->left->right=NULL;
    last=last->left;}
  }else
  

if(strcmp(com,"delete")==0){
   scanf("%d",&x);

/*要素1つの場合*/
if(root->right==NULL){if(root->num==x){free(root);root=NULL;last=NULL;}}

/*要素が2以上*/
else{

  if(root->num==x){/*先頭*/
       root->right->left=NULL;
       root=root->right;}

  else{p=root;
  
      while(p!=NULL){

        if(p->num==x){

          if(p->right==NULL){p->left->right=NULL;last=p->left;break;}
          else{

            p->right->left=p->left;
            p->left->right=p->right;
            p->right=NULL;}
        }

        p=p->right;


       }/*while終了*/


   }
}
}
}
p=root;
while(p!=NULL){

if(p->right==NULL){printf("%d\n",p->num);}
else{printf("%d ",p->num);}
p=p->right;

}



return 0;
}




