import scala.collection.mutable.Seq

object Main extends App {

  case class State[S, A](run: S => (S, A)) {
    def map[B](f: A => B) = State((s: S) => {
      val (s1, a) = run(s)
      (s1, f(a))
    })

    def flatMap[B](f: A => State[S, B]) = State((s: S) => {
      val (s1, a) = run(s)
      f(a).run(s1)
    })
  }

  object State {
    def unit[S, A](a: A): State[S, A] = State(s => (s, a))
  }

  implicit class ListOps[S, A](stlist: List[State[S, A]]) {
    def sequence: State[S, List[A]] =
      stlist.foldRight(State.unit[S, List[A]](List[A]()))((h: State[S, A], acc: State[S, List[A]]) => h.flatMap(a => acc.map(list => a :: list)))
  }

  def exec(a: Array[String]): State[Seq[Int], Unit] = State((s: Seq[Int]) => a match {
    case Array("deleteFirst") => (s.tail, ())
    case Array("deleteLast")  => (s.init, ())
    case Array("delete", x)   => (deleteX(s, x.toInt), ())
    case Array("insert", x)   => (x.toInt +: s, ())
  })

  def deleteX(s: Seq[Int], x: Int): Seq[Int] = {
    val index = s.indexOf(x)
    if (index != -1) {
      val (s1, s2) = s.splitAt(index)
      s1 ++ s2.tail
    } else {
      s
    }
  }

  val n   = readInt
  val ans = (1 to n)
    .map(_ => readLine.split(" "))
    .map(exec)
    .toList
    .sequence
    .run(Nil)
    ._1
    .mkString(" ")

  println(ans)
}
