import scala.io.StdIn.{readInt, readLine};
object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val list = new DoublyLinkedList();
        for (i <- (0 until n)) {
            val input = readLine.split(" ");
            if (input(0) == "insert") {
                list.insert(input(1).toLong);
            } else if (input(0) == "delete") {
                list.delete(input(1).toLong);
            } else if (input(0) == "deleteFirst") {
                list.deleteFirst;
            } else {
                list.deleteLast;
            }
        }
        println(list);
    }
}
class DoublyLinkedList() {
    case class Node(key: Long, var prev: Node, var next: Node);
    private val head = Node(-1L, null, null);
    def isEmpty: Boolean = head.next == null && head.prev == null;
    override def toString: String = {
        def go(node: Node, ret: List[Long]): List[Long] =  if (node.key == -1L) ret else go(node.prev, node.key :: ret);
        if (isEmpty) "" else go(head.prev, Nil).mkString(" ");
    }
    def insert(key: Long): Unit = {
        if (isEmpty) {
            val node = Node(key, head, head);
            head.next = node;
            head.prev = node;
        } else {
            val node = Node(key, head, head.next);
            head.next.prev = node;
            head.next = node;
        }
    }
    
    private def _delete(node: Node): Unit = {
        val prev = node.prev;
        val next = node.next;
        if (prev == head && next == head) {
            head.next = null;
            head.prev = null;
        } else {
            prev.next = next;
            next.prev = prev;
        }
    }
    
    private def find(node: Node, key: Long): Node = node.key match {
        case -1L => null;
        case `key` => node;
        case _ => find(node.next, key);
    }
    
    def delete(key: Long): Unit = {
        val target = find(head.next, key);
        if (target != null) _delete(target);
    }
    
    def deleteFirst: Unit = {
        _delete(head.next);
    }
    def deleteLast: Unit = {
        _delete(head.prev);
    }
}
