#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;
  newNode->prev = NULL;
  newNode->next = first;
  if (first != NULL)
    first->prev = newNode;
  first = newNode;
  if (last == NULL)
    last = newNode;
}

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->next->prev = current->prev;
	      current->prev->next = current->next;
	      free(current);
	    }
	  return;
	}
      current = current->next;
    }
}
	  
void deleteFirst()
{
  first = first->next;
  free(first->prev);
  first->prev = NULL;
}

void deleteLast()
{
  last = last->prev;
  free(last->next);
  last->next = NULL;
}

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

