import scala.io.StdIn.{readInt, readLine};
object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val list = new DoublyLinkedList[Long]();
        for (i <- (0 until n)) {
            readLine.split(" ") match {
                case Array("insert", value) => list.insert(value.toLong);
                case Array("delete", value) => list.delete(value.toLong);
                case Array("deleteFirst") => list.deleteFirst;
                case Array("deleteLast") => list.deleteLast;
                case _ => ();
            }
        }
        println(list);
    }
}
class DoublyLinkedList[A]() {
    trait Node {var prev: Node; var next: Node;}
    case class Head(var prev: Node, var next: Node) extends Node;
    case class Elem(key: A, var prev: Node, var next: Node) extends Node;
    var length = 0;
    private val head = Head(null, null);
    def isEmpty: Boolean = length == 0;
    override def toString: String = {
        def go(node: Node, ret: List[A]): List[A] = {
            node match {
                case e: Elem => go(e.prev, e.key :: ret);
                case _ => ret;
            }
        }
        if (isEmpty) "" else go(head.prev, Nil).mkString(" ");
    }
    def insert(key: A): Unit = {
        if (isEmpty) {
            val e = Elem(key, head, head);
            head.next = e;
            head.prev = e;
        } else {
            val e = Elem(key, head, head.next);
            head.next.prev = e;
            head.next = e;
        }
        length += 1;
    }
    def delete(key: A): Unit = {
        def go(node: Node): Elem = {
            node match {
                case e: Elem => if (e.key == key) e else go(e.next);
                case _ => null;
            }
        }
        if (!isEmpty) {
            if (length == 1) {
                deleteFirst;
            } else {
                go(head.next) match {
                    case null => ();
                    case e => {
                        val n = e.next;
                        val p = e.prev;
                        n.prev = p;
                        p.next = n;
                        length -= 1;
                    }
                }
            }
        }
    }
    
    def deleteFirst: Unit = {
        if (!isEmpty) {
            if (length == 1) {
                head.next = null;
                head.prev = null;
            } else {
                val newFirst = head.next.next;
                newFirst.prev = head;
                head.next = newFirst;
            }
            length -= 1;
        }
    }
    def deleteLast: Unit = {
        if (!isEmpty) {
            if (length == 1) {
                head.next = null;
                head.prev = null;
            } else {
                val newLast = head.prev.prev;
                newLast.next = head;
                head.prev = newLast;
            }
            length -= 1;
        }
    }
}
