import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.{ForkJoinPool, RecursiveTask}

import scala.annotation.tailrec
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readInt()
  val list = StdIn.readLine().split(" ").toList.map(_.toInt)

  val count = new AtomicInteger(0)

  val pool = new ForkJoinPool()

  class AggregateTask(list: List[Int]) extends RecursiveTask[List[Int]] {
    override def compute(): List[Int] = {
      val n = list.length / 2
      if (n == 0) {
        list
      } else {
        val (left, right) = list.splitAt(n)
        val leftTask = new AggregateTask(left)
        val rightTask = new AggregateTask(right)
        leftTask.fork()
        rightTask.fork()
        merge(leftTask.join(), rightTask.join())
      }
    }

    private[this] def merge(left: List[Int], right: List[Int]): List[Int] = {
      @tailrec
      def mergeRec(left: List[Int], right: List[Int], merged: List[Int]): List[Int] = {
        if (left.nonEmpty || right.nonEmpty) count.incrementAndGet()
        (left.isEmpty, right.isEmpty) match {
          case (true, true) => merged
          case (true, false) => mergeRec(left, right.tail, right.head :: merged)
          case (false, true) => mergeRec(left.tail, right, left.head :: merged)
          case _ =>
            (left.head, right.head) match {
              case (l, r) if l < r => mergeRec(left.tail, right, l :: merged)
              case (_, r) => mergeRec(left, right.tail, r :: merged)
            }
        }
      }

      mergeRec(left, right, List()).reverse
    }
  }

  val sortedList = pool.invoke(new AggregateTask(list))
  println(sortedList.mkString(" "))
  println(count)
}