/*
   双方向リストの実装
   　insert x: リストの先頭にxをもつ要素を追加
   　delete x: キーxを持つ最初のリストを削除
     deleteFirst : リストの最初の要素を削除
     deleteLast : リストの末尾の要素を削除

     入力
     n
     command1 a
     command2 b
     commandn c

     出力
     すべてのcommandが終了したあとの連結リストのキーを
     順番に出力。
     連続するキーは空白で区切る。
*/

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

struct node {
   unsigned int key;
   struct node *next;
   struct node *prev;
};

typedef struct node *NodePointer;

NodePointer nil;

void init()
{
   nil = (struct node *)malloc(sizeof(struct node));
   nil->next = nil;
   nil->prev = nil;

}

void insert(unsigned int key)
{
   NodePointer x;
   x = (struct node *)malloc(sizeof(struct node));
   x->key = key;

   x->next = nil->next;
   nil->next->prev = x;
   nil->next = x;
   x->prev = nil;

}

void deleteNode(NodePointer t)
{
   t->prev->next = t->next;
   t->next->prev = t->prev;
   free(t);
}

NodePointer searchList(unsigned int p)
{
   NodePointer cur = nil->next;

   while ( cur != nil && cur->key != p)
      cur = cur->next;

   return cur;

}

void deleteFirst()
{
   NodePointer t = nil->next;
   if (t == nil)
      return;
   deleteNode(t);
}

void deleteLast()
{
   NodePointer t = nil->prev;
   if (t == nil)
      return;
   deleteNode(t);
}

void delete(int key)
{
   deleteNode(searchList(key));
}

void printList()
{
   NodePointer cur = nil->next;
   int isf = 1;

   while (1) {
      if (cur == nil) break;

      if (isf == 0) printf(" ");

      printf("%d", cur->key);

      isf = 0;
      if (cur->next == nil)
         isf = 1;

      cur = cur->next;
   }

   printf("\n");
}

int main()
{
   int n;
   unsigned int key;
   char com[12];
   scanf("%d", &n);

   init();

   while (n) {
      scanf("%s%d", com, &key);
      if (com[0] == 'i')
         insert(key);
      else if ( com[0] == 'd' ) {
         if ( strlen(com) > 6 ) {
            if ( com[6] == 'F')
               deleteFirst();
            else if ( com[6] == 'L')
               deleteLast();
         } else {
            delete(key);
         }
      }
      n--;
   }

   printList();

   return 0;
}
