def merge(a, left, mid, right)
    n1 = mid - left
    n2 = right - mid
    l = []
    r = []
    for i in 0..n1 - 1
        l[i] = a[left + i]
    end 
    for i in 0..n2 - 1
        r[i] = a[mid + i]
    end
    l[n1] = Float::INFINITY
    r[n2] = Float::INFINITY
    i = 0
    j = 0
    for k in left..right-1
        $n += 1
        if l[i] <= r[j] then
            a[k] = l[i]
            i += 1
        else
            a[k] = r[j]
            j += 1
        end
    end
    return a
end

def mergeSort(a, left, right)
    if left + 1 < right then
        mid = (left + right) / 2
        mergeSort(a, left, mid)
        mergeSort(a, mid, right)
        return merge(a, left, mid, right)
    else
        return a
    end
    
end

$n = 0
gets
s = gets.split.map(&:to_i)
left = 0
right = s.length
s = mergeSort(s, left, right)

puts s.join(" ")
puts $n
