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

object Main {
  def merge(a:Array[Int],left:Int,mid:Int,right:Int):Int = {
    val n1 = mid-left
    val n2 = right-mid
    var count = 0
    val l = a.slice(left,left+n1) ++ Array(Int.MaxValue)
    val r = a.slice(mid,mid+n2) ++ Array(Int.MaxValue)
    var i=0
    var j=0
    for(k<-left until right) {
      if(l(i)<=r(j)){
        a(k) = l(i)
        i += 1
      } else  {
        a(k)=r(j)
        j += 1
      }
      count += 1
    }
    count
  }

  def mergeSort(a:Array[Int],left:Int,right:Int,cnt:Int):Int = {
    if(left+1>=right) cnt
    else {
      val mid = (left+right)/2
      val x = mergeSort(a,left,mid,cnt)
      val y = mergeSort(a,mid,right,cnt)
      val z = merge(a,left,mid,right)
      x+y+z
    }
  }

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