//config = {input: 'tmp', newline: '\r\n'}; // win
config = {input: '/dev/stdin', newline: '\n'}; //linux

function DoublyLinkedList() {
  this.head = null;
  this.tail = null;
}

DoublyLinkedList.prototype.insert = function(x) {
  var old_head = this.head;
  this.head = { prev: null, next: old_head, value: x };
  if (old_head !== null) old_head.prev = this.head;
  if (this.tail === null) this.tail = this.head;
};

DoublyLinkedList.prototype.delete = function(x) {
  var it = this.head;
  while (it !== null) {
    if (it.value !== x) {
      it = it.next;
      continue;
    }
    if (this.head === it) this.head = it.next;
    if (this.tail === it) this.tail = it.prev;
    if (it.prev !== null) it.prev.next = it.next;
    if (it.next !== null) it.next.prev = it.prev;
    break;
  }
};

DoublyLinkedList.prototype.deleteFirst = function() {
  this.head = this.head.next;
  if (this.head === null) this.tail = null;
  else this.head.prev = null;
};

DoublyLinkedList.prototype.deleteLast = function() {
  this.tail = this.tail.prev;
  if (this.tail === null) this.head = null;
  else this.tail.next = null;
};

DoublyLinkedList.prototype.toString = function() {
  var it = this.head, ary = [];
  while (it !== null) {
    //ary.push((it.prev !== null) ? it.prev.value : 'null');
    //ary.push((it.next !== null) ? it.next.value : 'null');
    ary.push(it.value);
    it = it.next;
  }
  return ary.join(' ');
};

lst = new DoublyLinkedList();

require('fs').readFileSync(config.input, 'ascii')
  .split(config.newline)
  .forEach(function (line) {
    var inst = line.split(' '), op = inst[0];
    if (op === 'insert') lst.insert(parseInt(inst[1], 10));
    else if (op === 'delete') lst.delete(parseInt(inst[1], 10));
    else if (op === 'deleteFirst') lst.deleteFirst();
    else if (op === 'deleteLast') lst.deleteLast();
  });

console.log(lst.toString());