//以下の命令を受け付ける双方向連結リスト
//insert x
//delete x
//deleteFirst
//deleteLast
#include <iostream>

template <class T>
class Doubly_Linked_List{
public:
  struct Node{
    Node* prev;
    Node* next;
    T value;
  };
private:
  Node* top;
  Node* end;

public:
  Doubly_Linked_List();
  void insert(T val);
  void del(T key);
  void deleteFirst();
  void deleteLast();
  void printList();
};

template <class T>
Doubly_Linked_List<T>::Doubly_Linked_List(){
  top = nullptr;
  end = nullptr;
}

template <class T>
void Doubly_Linked_List<T>::insert(T val){
  Node* new_node = new Node;
  new_node->value = val;
  new_node->prev = nullptr;
  if(top==nullptr){
    new_node->next = nullptr;
    end = new_node;
  }
  else {
    new_node->next = top;
    top->prev = new_node;
  }
  top = new_node;
  return;
}

template <class T>
void Doubly_Linked_List<T>::del(T key){
  Node* node_ptr = top;
  while(node_ptr){
    if(node_ptr->value == key){
      Node* n1 = node_ptr->prev;
      Node* n2 = node_ptr->next;
      if(n1 == nullptr & n2 == nullptr){
        top = nullptr;
        end = nullptr;
      }
      else if(n1 == nullptr){
        //これはnode_ptrがtopの時に起きる。
        n2->prev = nullptr;
        top = n2;
      }
      else if(n2 == nullptr){
        //これはnode_ptrがendの時に起きる。
        end = n1;
        end->next = nullptr;
      }
      else{
        n1->next = n2;
        n2->prev = n1;
      }
      delete node_ptr;
      return;
    }
    node_ptr = node_ptr->next;
  }
  return;
}

template <class T>
void Doubly_Linked_List<T>::deleteFirst(){
  if(top==nullptr){
    return;
  }
  top = top->next;
  if(top==nullptr){
    end = nullptr;
  }else{
    delete top->prev;
    top->prev = nullptr;
  }
  return;
}

template <class T>
void Doubly_Linked_List<T>::deleteLast(){
  if(end==nullptr){
    return;
  }
  end = end->prev;
  if(end == nullptr){
    top = nullptr;
  }else{
    delete end->next;
    end->next = nullptr;
  }
}

template <class T>
void Doubly_Linked_List<T>::printList(){
  Node* node_ptr = top;
  if(node_ptr == nullptr){
    return;
  }
  while(node_ptr->next){
    std::cout << node_ptr->value << ' ';
    node_ptr = node_ptr->next;
  }
  std::cout << node_ptr->value;
}

enum Command {
  INSERT = 0,
  DELETE = 1,
  DELETEFIRST = 2,
  DELETELAST = 3,
  INVALID = 4,
};

Command compare(std::string command){
  if(command == "insert") return INSERT;
  if(command == "delete") return DELETE;
  if(command == "deleteFirst") return DELETEFIRST;
  if(command == "deleteLast") return DELETELAST;
  return INVALID;
}

int main(){
  int n;
  std::cin >> n;
  std::string command;
  Doubly_Linked_List<int>* DLL = new Doubly_Linked_List<int>();
  int x = 0;
  for(int i = 0; i < n ; i++){
    std::cin >> command;
    switch (compare(command)) {
      case INSERT:
        std::cin >> command;
        x = std::stoi(command);
        DLL->insert(x);
        break;
      case DELETE:
        std::cin >> command;
        x = std::stoi(command);
        DLL->del(x);
        break;
      case DELETEFIRST:
        DLL->deleteFirst();
        break;
      case DELETELAST:
        DLL->deleteLast();
        break;
      case INVALID:
        std::cout << "invalid command.";
        break;
    }
  }
  DLL->printList();
  std::cout << std::endl;
  delete DLL;
  return 0;
}



Measured memory_bytes: 34412