import scala.io.StdIn
import scala.annotation.tailrec

object Main{
  def main(args: Array[String]){
    StdIn.readLine()
    val line = StdIn.readLine().split(" ").toList.map(_.toInt)

    val res = bSort(List(), line, 0)
    println(res._2.mkString(" ") + "\n" + res._1)
  }

  @tailrec
  def bSort(sorted: List[Int], unsorted: List[Int], n: Int): Tuple2[Int, List[Int]] ={
    if(unsorted.length == 0) (n, sorted)
    else if(unsorted.sorted == unsorted) (n, sorted ::: unsorted)
    else bSort(sorted :+ unsorted.min, unsorted.filter(_ == unsorted.min), n+1)
  }
}