import scala.io.StdIn._
import scala.collection.mutable

object Main extends App {
  
  var cnt = 0
  def merge(A: Array[Int], left: Int, mid: Int, right: Int) {
    val n1 = mid - left
    val n2 = right - mid
    val L = A.slice(left, left + n1) :+ Int.MaxValue
    val R = A.slice(mid, mid + n2) :+ Int.MaxValue
    var i = 0
    var j = 0
    for (k <- (left to right - 1)) {
      if (L(i) <= R(j)) {
        A(k) = L(i)
        i += 1
      } else {
        A(k) = R(j)
        j += 1
      }
      cnt += 1
    }
  }
  def mergeSort(A: Array[Int], left: Int, right: Int) {
    if (left + 1 < right) {
      val mid = (left + right) / 2
      mergeSort(A, left, mid)
      mergeSort(A, mid, right)
      merge(A, left, mid, right)
    }
  }

  val N = readLine.toInt
  val A = readLine.split(" ").map(_.toInt)
  mergeSort(A, 0, A.size)
  println(A.mkString(" "))
  println(cnt)
}
