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

object Main {
  var cnt = 0

  def merge(a:Array[Int],left:Int,mid:Int,right:Int) = {
    var i=0
    var j=0
    val n1 = mid-left
    val n2 = right-mid
    val l = a.slice(left,left+n1) ++ Array(Int.MaxValue)
    val r = a.slice(mid,mid+n2) ++ Array(Int.MaxValue)
    i=0;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
      }
      cnt += 1
    }
  }

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

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    mergeSort(a,0,n)
    for(i<-0 until a.length) {
      print(a(i))
      if(i!=a.length-1) print(" ")
      else println
    }
    println(cnt)
  }
}