object Main
  extends App {
  val N        = readInt
  val initList = readLine.split(" ").map(_.toInt).toList

  (0 until N).foldLeft(initList)((acc, h) => sortAndPrint(acc, h))

  def sortAndPrint(list: List[Int], i: Int): List[Int] = {
    val target = list(i)
    val left = list.take(i)
    val right = list.drop(i + 1)
    val insertIndex = left.dropWhileRight(target <= _).length
    val newList = left.take(insertIndex) ++ List(target) ++ left.drop(insertIndex) ++ right
    println(newList.mkString(" "))
    newList
  }

  implicit class RichList[A](l: List[A]) {
    def dropWhileRight(f: A => Boolean): List[A] = {
      l.reverse.dropWhile(f).reverse
    }
  }
}

