object Main {
  def main(args: Array[String]): Unit = {
    val (n, s) = (io.StdIn.readLine().toInt, io.StdIn.readLine().split(' ').map(_.toInt).toList)

    var cnt = 1
    def merge(left: List[Int], right: List[Int]): List[Int] = (left, right) match {
      case (x :: xs, y :: ys) if x <= y =>
        cnt += 1
        x :: merge(xs, right)
      case (x :: xs, y :: ys) if x > y =>
        cnt += 1
        y :: merge(left, ys)
      case (Nil, ys) =>
        cnt += 1
        right
      case (xs, Nil) =>
        cnt += 1
        left
    }

    def mergeSort(list: List[Int]): List[Int] = list match {
      case x :: Nil => list
      case _ =>
        val (l1, l2) = list.splitAt(list.size / 2)
        merge(mergeSort(l1), mergeSort(l2))
    }
    println(mergeSort(s).mkString(" "))
    println(cnt)
  }
}