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

object Main {
  var cnt = 0
  var a = new Array[Int](0)
  var l = new Array[Int](0)
  var r = new Array[Int](0)
  var i=0
  var j=0

  def merge(left:Int,mid:Int,right:Int) = {
    val n1 = mid-left
    val n2 = right-mid
    l = a.slice(left,left+n1) ++ Array(Int.MaxValue)
    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(left:Int,right:Int):Unit = {
    if(left+1>=right) return
    else {
      val mid = (left+right)/2
      mergeSort(left,mid)
      mergeSort(mid,right)
      merge(left,mid,right)
    }
  }

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