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

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

typedef struct node *NodePointer

Nodepointer nil;

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

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

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 deleteNode(NodePointer t)
{
  t->prev->next = t->next;
  t->next->prev = t->prev; 
}



void delete(int key)
{
  NodePointer x;
  x = listSearch(key);  
  if(x != NULL)
    {
      if(x == nil)
	{
	  return;
	}

      deleteNode(x);
    }
}


main()
{
  int n, i, key, np, nd;
  char com[20];
  NodePointer a;

  scanf("%d", &n);
  init();

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

      if(com[0] == 'i')
	{
	  insert(key);
	  np++;
	  size++;
	}
      else if(com[0] == 'd')
	{
	  if(strlen(com) > 6)
	    {
	      if(com[6] == 'F')
		{
		  deleteFirst();
		}
	      else if(com[6] == 'L')
		{
		  deleteLast();
		}
	      else
		{
		  delete(key);
		  nd++;
		}
	      size--;
	    }
	}
    }



  return 0;
}