import scala.io.StdIn.{readLine,readInt}

object Main {
  var cnt = 0

  def merge(al:Array[Int],ar:Array[Int]):Array[Int] = {
    var i=0
    var j=0
    val l = al ++ Array(Int.MaxValue)
    val r = ar ++ Array(Int.MaxValue)
    val newa = new Array[Int](al.length+ar.length)
    for(k<-0 until al.length+ar.length) {
      if(l(i)<=r(j)){
        newa(k) = l(i)
        i += 1
      } else {
        newa(k)=r(j)
        j += 1
      }
      cnt += 1
    }
    newa
  }

  def mergeSort(a:Array[Int]):Array[Int] = {
    if(a.length==1) a
    else {
      val mid = a.length/2
      merge(mergeSort(a.slice(0,mid)),mergeSort(a.slice(mid,a.length)))
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val b = mergeSort(a)
    println(b.mkString(" "))
    println(cnt)
  }
}