#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>

#define MAX_STACKS 102
#define MAX_DEQUE 100001

struct Data{
  int time;
  char name[16];
};

class List{
  struct list_element{
    int key;
    list_element* back;
    list_element* next;
  };
  list_element list_top = { 0, nullptr, nullptr };
  list_element* list_end = &list_top;
  size_t list_size = 1;
public:
  void list_insert( int x ){
    list_element* l = new list_element;
    l->key = x;
    list_end->next = l;
    l->back = list_end;
    l->next = nullptr;
    list_end = l;
    list_size++;
  }

  void list_delete( int x ){
    list_element* l = list_end;
    while( l != &list_top ){
      if( l->key == x ){
        l->back->next = l->next;
        if( l->next == nullptr ){
          list_end = l->back;
        } else {
          l->next->back = l->back;
        }
        delete l;
        list_size--;
        break;
      }
      l = l->back;
    }
  }

  void list_deleteFirst(){
    if( list_end == nullptr ) return;
    list_element* l = list_end->back;
    delete list_end;
    list_end = l;
    list_end->next = nullptr;
    list_size--;
  }

  void list_deleteLast(){
    if( list_top.next == nullptr ) return;
    list_element* l = list_top.next->next;
    if( l != nullptr ){
      l->back = &list_top;
      delete list_top.next;
      list_top.next = l;
      list_size--;
    } else {
      delete list_top.next;
      list_top.next = nullptr;
      list_end = &list_top;
      list_size--;
    }
  }

  void list_print(){
    for( list_element* l = list_end; l != &list_top; l = l->back ){
      std::cout << l->key;
      if( l->back != &list_top )  std::cout << " ";
    }
    std::cout << std::endl;
  }
};

class Deque{
  Data* addrs[MAX_DEQUE] = { 0 };

  int head = 0;
  int tail = 0;
public:
  void printDeque(){
    int idx = head;
    for( idx; idx >tail; idx-- ){
      std::cout << idx << ": " << addrs[idx]->time << "    " << addrs[idx]->name << std::endl;
    }
  }

  void enque( Data& d ){
    if( head >= MAX_DEQUE-1 ){
      head = 0;
    } else {
      head++;
    }
    addrs[head] = new Data;
    *addrs[head] = d;
    return;
  }

  Data deque(){
    tail++;
    if( tail >= MAX_DEQUE ) tail = 0;
    Data ret = *addrs[tail];
    delete addrs[tail];
    return ret;
  }

  bool isEmpty(){
    return head == tail;
  }

};

class Stack{
  int* addrs[MAX_STACKS];
  unsigned int top = 0;
public:
  int pop(){
    if( top <= 0 ){
      std::cerr << "No stacks" << std::endl;
      exit(0);
    }

    int n = *(addrs[top]);
    delete addrs[top];
    top--;
    return n;
  }
  void push( int num ){
    if( top >= MAX_STACKS - 1 ){
      std::cerr << "Stacks max" << std::endl;
      exit( 0 );
    }
    top++;
    addrs[top] = new int;
    *(addrs[top]) = num;
    return;
  }
};

int main(){
  List list;
  int N;
  std::cin >> N;
  char instruct[16];
  int x;
  for( int i = 0; i < N; i++ ){
    std::cin >> instruct;
    if( !strcmp( instruct, "insert" ) ){
      std::cin >> x;
      list.list_insert( x );
    }
    else if( !strcmp( instruct, "delete" ) ){
      std::cin >> x;
      list.list_delete( x );
    }
    else if( !strcmp( instruct, "deleteFirst" ) ){
      list.list_deleteFirst();
    }
    else if( !strcmp( instruct, "deleteLast" ) ){
      list.list_deleteLast();
    }
    else {
      std::cout << "Not define instruction" << std::endl;
    }
    //list.list_print();
  }

  list.list_print();
}



Measured memory_bytes: 34384