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

typedef struct LinkedList
{
  struct LinkedList *prev;
  int key;
  struct LinkedList *next;
} LinkedList;

LinkedList *first = NULL;
LinkedList *last = NULL;

void insert(int);
void deleteKey(int);
void deleteFirst();
void deleteLast();
void printLinkedList();

int main(void)
{
  int numOp, i, key;
  char command[12];
  scanf(" %d", &numOp);
  for (i = 0; i < numOp; i++)
    {
      scanf(" %s", command);
      if (!strcmp(command, "insert"))
	{
	  scanf(" %d", &key);
	  insert(key);
	}
      else if (!strcmp(command, "delete"))
	{
	  scanf(" %d", &key);
	  deleteKey(key);
	}
      else if (!strcmp(command, "deleteFirst"))
	deleteFirst();
      else
	deleteLast();
    }
  printLinkedList();
  return 0;  
}

void insert(int key)
{
  LinkedList *newNode = (LinkedList *) malloc(sizeof(LinkedList));
  newNode->key = key;
  if (first == NULL)
    {
      first = newNode;
      last = newNode;
      newNode->prev = NULL;
      newNode->next = NULL;
    }
  else
    {
      newNode->next = first;
      first->prev = newNode;
      first = newNode;
    }
  return;
}

void deleteKey(int key)
{
  LinkedList *current = first;
  while (current != NULL)
    {
      if (current->key == key)
	{
	  if (current == first)
	    deleteFirst();
	  else if (current == last)
	    deleteLast();
	  else
	    {
	      current->prev->next = current->next;
	      current->next->prev = current->prev;
	      free(current);
	    }
	  return;
	}
      current = current->next;
    }
  return;
}
	  
void deleteFirst()
{
  if (!first)
    return;
  if (first == last)
    {
      free(first);
      first = NULL;
      last = NULL;
    }
  else
    {
      LinkedList *holder = first->next;
      free(first);
      first = holder;
      first->prev = NULL;
    }
  return;
}

void deleteLast()
{
  if (!last)
    return;
  if (first == last)
    {
      free(last);
      first = NULL;
      last = NULL;
    }
  else
    {
      LinkedList *holder = last->prev;
      free(last);
      last = holder;
      last->next = NULL;
    }
  return;
}

void printLinkedList()
{
  LinkedList *current = first;
  while (current != NULL)
    {
      printf("%d", current->key);
      if (current == last)
	{
	  printf("\n");
	  break;
	}
      else
	printf(" ");
      current = current->next;
    }
}


