def demerge(ary, count)

  if ary.size > 1

    divisor  = ary.size/2 - 1
    ary_1stH = ary[0 .. divisor]
    ary_2ndH = ary[divisor + 1 .. ary.size - 1]

    demerge(ary_1stH, count)
    demerge(ary_2ndH, count)

    merge(ary_1stH, ary_2ndH, ary, count)
  end
end

def merge(ary_1stH, ary_2ndH, ary, count)

  size = 0

  while ary_1stH.size > 0 && ary_2ndH.size > 0

    count[0] += 1

    if ary_1stH[0] < ary_2ndH[0]
      ary[size] = ary_1stH.shift
      size += 1
    else
      ary[size] = ary_2ndH.shift
      size += 1
    end
  end

  if ary_1stH.size > 0

    ary[size .. size + ary_1stH.size - 1] = ary_1stH
    size     += ary_1stH.size - 1
    count[0] += ary_1stH.size
  end

  if ary_2ndH.size > 0

    ary[size .. size + ary_2ndH.size - 1] = ary_2ndH
    size     += ary_2ndH.size - 1
    count[0] += ary_2ndH.size
  end
end

size_of_ary = gets.to_i
ary         = gets.split.map &:to_i

count       = [0]
demerge(ary, count)

puts ary.join(" "), count[0]

