import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ListBuffer

object Main {
  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) ++ 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
      }
      cnt += 1
    }
  }

  def sort(n:Int,l:List[(Int,Int)]):List[(Int,Int)] = {
    if(n==1) l
    else if(l==Nil) {
      sort(n/2,List((0,n/2),(n/2,n)))
    } else {
      val newl = new ListBuffer[(Int,Int)]
      for(i<-l) {
        val mid = (i._2+i._1)/2
        newl += ((i._1,mid))
        newl += ((mid,i._2))
      }
      sort(n/2,newl.toList)
    }
  }

  def mergeSort(n:Int,l:List[(Int,Int)],a:Array[Int]):Unit = {
    if(l.length==1) return
    else {
      var i = 0
      var left = 0
      var right = 0
      val b = new ListBuffer[(Int,Int)]
      for(e<-l) {
          val mid = (e._2+e._1)/2
          if(e._2-e._1>1)
            merge(a,e._1,mid,e._2)
          if(i==1) {
            right = e._2
            b += ((left,right))
            i = 0
          } else {
            left = e._1
            i+=1
          }
      }
      mergeSort(n,b.toList,a)
    }
  }

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