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

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
    }
  }

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

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val r = sort(n,Nil)
    for(list<-r) {
      for(e <- list) {
        if(e._2-e._1>1){
          val mid = (e._2+e._1)/2
          merge(a,e._1,mid,e._2)
        }
      }
    }
    println(a.mkString(" "))
    println(cnt)
  }
}