#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define DLINKMAXSIZE (2000000)
#define OPELANDLEN (100)

typedef struct _dlink{
  struct _dlink *prev;
  struct _dlink *next;
  int data;
} dlink;

dlink linkbuf[DLINKMAXSIZE];

dlink *dlfst = NULL;
dlink *dllst = NULL;
unsigned int dl_next_alloc =0;


dlink *dlink_new_link_element(void)
{
  dlink *newelement = &linkbuf[dl_next_alloc];
  dl_next_alloc ++;
  return (newelement);
}


void dlink_insert(int x)
{
  dlink *data;

  data = dlink_new_link_element();
  data->data = x;
  if(dlfst != NULL)
  {
    data->next = dlfst;
    data->next->prev = data;
  }else{
    dllst = data;
    dllst->next = NULL;
  }
  dlfst = data;
  dlfst->prev = NULL;
}

void dlink_delete(int x)
{
  dlink *nowp = dlfst;

  do{
    if (nowp->data ==x)
      break;

    nowp = nowp->next;
  }while(nowp != NULL);

  if (nowp == NULL)
    return;
  if (nowp->prev == NULL)
    dlfst = nowp->next;
  else
    nowp->prev->next = nowp->next;

  if (nowp->next == NULL)
    dllst = nowp->prev;
  else
    nowp->next->prev = nowp->prev;
}

void dlink_deleteFirst(void)
{
  dlfst = dlfst->next;
  if(dlfst != NULL)
    dlfst->prev = NULL;
  else
    dllst = NULL;
}

void dlink_deleteLast(void)
{
  dllst = dllst->prev;
  if (dllst != NULL)
    dllst ->next = NULL;
  else
    dlfst =NULL;
}


int dlink_opecheck(char *ope)
{
  char *elem[2];
  int data;
  char opecpy[100];
  strcpy(opecpy, ope);

  elem[0] = strtok(opecpy, " \n");
  elem[1] = strtok(NULL, " ");

  if (strcmp(elem[0], "insert") == 0)
  {
    data = atoi(elem[1]);
    dlink_insert(data);
  }

  if (strcmp(elem[0], "delete") == 0)
  {
    data = atoi(elem[1]);
    dlink_delete(data);
  }
  if (strcmp(elem[0], "deleteFirst") == 0)
    dlink_deleteFirst();

  if (strcmp(elem[0], "deleteLast") == 0)
    dlink_deleteLast();
}

void printdata(void)
{
  dlink *nowp = dlfst;
  while (nowp != NULL){
    printf("%d%c",nowp->data, (nowp->next)?' ':'\n');
    nowp = nowp->next;
  }
}
int main(void)
{
  char ope[OPELANDLEN];
  int count, i, j;

  fgets(ope, OPELANDLEN, stdin);

  count = atoi(ope);
  for ( i = 0; i <count; i++)
  {
    fgets(ope, OPELANDLEN, stdin);
    dlink_opecheck(ope);
//    printf("%s\t\t:", strtok(ope, "\n");
//    printdata();
  }
  printdata();
}
