#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;

int InsertionSort(vector<int>& Array, int N, int g)
{
  	int count = 0;
  	for(int i = g; i< N;i++)
    {
    	int tmp = Array[i];
	  	int j = i -g;
      	while(j>=0 && Array[j] > tmp)
        {
          	Array[j+g] = Array[j];
          	j = j-g;
          	count++;
        }
    	Array[j+g] = tmp;
    }
  	return count;
}

void ShellSort(vector<int> Array, int N)
{
  	int count=0;
  	vector<int> G;
  	G.push_back(1);
  	int g=G[0];
  	while(N > g*3+1)
    {
      g=g*3+1;
      G.push_back(g);
    }
  	int m = G.size();
  	for(int i=m-1;i>=0;i--)
    {
      count+=InsertionSort(Array, N, G[i]);
    }
  	cout << m << endl;
  	for(int i=m-1;i>0;i--) cout << G[i] << " ";
  	cout << G[0] << endl;
  	cout << count << endl;
  	for(int i=0;i<N;i++) cout << Array[i] << endl;
}

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
}

class Node;
Node* p;

class Node
{
public:
  long key;
  Node* prev;
  Node* next;
  Node(){}
  Node(long v)
  {
    key=v;
    prev = nullptr;
    next = nullptr;
  }
  
  void insert(long v)
  {
    Node* n = new Node(v);
    next = n;
    n->prev = this;
    n->next = p;
    p->prev = n;
  }
  
  Node* searchNode(long v)
  {
    Node* cur = p->prev;
    while(cur != p && cur->key != v) cur = cur->prev;
    return cur;
  }
  
  void deleteNode(Node* n)
  {
    if(n == p) return;
    n->prev->next = n->next;
    n->next->prev = n->prev;
    delete n;
  }
  
  void deleteKey(long v)
  {
    deleteNode(searchNode(v));
  }
  
  void deleteFirst()
  {
    deleteNode(p->prev);
  }
  
    void deleteLast()
  {
    deleteNode(p->next);
  }

};

void init()
{
  p = new Node();
  p->next = p;//最後
  p->prev = p;//先頭
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
  	cin >> n;
  	//vector< pair<string, long> > p;
	//vector<long> A(N);
  	int idx = 0;
  	//while(cin >> A[idx]) idx++;
  	string command;
  	long num;
  	//vector<long> elem;
  	init();
  	while(cin >> command)
    {
      if(command == "insert")
      {
        cin >> num;
        if(p->prev == p) p->insert(num);
        else p->prev->insert(num);
      }
      else if(command == "delete")
      {
        cin >> num;
        p->deleteKey(num);
      }
      else if(command == "deleteFirst")
      {
        p->deleteFirst();
      }
      else if(command == "deleteLast")
      {
        p->deleteLast();
      }
      idx++;
      if(idx == n) break;
    }
  	Node* o = p->prev;
  	while(p->next != o)
    {
      cout << o->key << " ";
      o = o->prev;
    }
  	cout << p->next->key << endl;
  	return 0;
}



Measured memory_bytes: 34492