def merge(a, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    l = a[left:left + n1] + [sentinel]
    r = a[mid:mid + n2] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
    count += right - left


def merge_sort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

sentinel = 10 ** 10

n = int(input())
a = list(map(int, input().split()))
count = 0
merge_sort(a, 0, len(a))
print(*a)
print(count) def merge(a, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    l = a[left:left + n1] + [sentinel]
    r = a[mid:mid + n2] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
    count += right - left merge global count n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid l = a[left:left + n1] + [sentinel] l a[left:left + n1] + [sentinel] a[left:left + n1] a left:left + n1 left left + n1 left n1 [sentinel] sentinel r = a[mid:mid + n2] + [sentinel] r a[mid:mid + n2] + [sentinel] a[mid:mid + n2] a mid:mid + n2 mid mid + n2 mid n2 [sentinel] sentinel i = j = 0 i 0 = j = 0 j 0 for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
     k range(left, right) range left right if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
     l[i] <= r[j] l[i] l i r[j] r j a[k] = l[i] a[k] a k l[i] l i i += 1 i 1 a[k] = r[j] a[k] a k r[j] r j j += 1 j 1 count += right - left count right - left right left a a left left mid mid right right def merge_sort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) merge_sort if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 merge_sort(a, left, mid) merge_sort a left mid merge_sort(a, mid, right) merge_sort a mid right merge(a, left, mid, right) merge a left mid right a a left left right right sentinel = 10 ** 10 sentinel 10 ** 10 10 10 n = int(input()) n int(input()) int input() input a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split count = 0 count 0 merge_sort(a, 0, len(a)) merge_sort a 0 len(a) len a print(*a) print *a a print(count) print count sentinel = 10 ** 10 10 ** 10 sentinel def merge(a, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    l = a[left:left + n1] + [sentinel]
    r = a[mid:mid + n2] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
    count += right - left def merge(a, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    l = a[left:left + n1] + [sentinel]
    r = a[mid:mid + n2] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
    count += right - left merge count = 0 0 count def merge_sort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) def merge_sort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) merge_sort n = int(input()) int(input()) n a = list(map(int, input().split())) list(map(int, input().split())) a
def merge(a, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    l = a[left:left + n1] + [sentinel]
    r = a[mid:mid + n2] + [sentinel]
    i = j = 0
    for k in range(left, right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1
    count += right - left


def merge_sort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

sentinel = 10 ** 10

n = int(input())
a = list(map(int, input().split()))
count = 0
merge_sort(a, 0, len(a))
print(*a)
print(count)