def merge(a, l, m, r):
    global cnt
    ll = a[l:m] + [1e9 + 1]
    rl = a[m:r] + [1e9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if ll[i] < rl[j]:
            a[k] = ll[i]
            i += 1
        else:
            a[k] = rl[j]
            j += 1
        cnt += 1


def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r)


n, a, cnt = int(input()), list(map(int, input().split())), 0
merge_sort(a, 0, n)
print(*a)
print(cnt) def merge(a, l, m, r):
    global cnt
    ll = a[l:m] + [1e9 + 1]
    rl = a[m:r] + [1e9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if ll[i] < rl[j]:
            a[k] = ll[i]
            i += 1
        else:
            a[k] = rl[j]
            j += 1
        cnt += 1 merge global cnt ll = a[l:m] + [1e9 + 1] ll a[l:m] + [1e9 + 1] a[l:m] a l:m l m [1e9 + 1] 1e9 + 1 1e9 1 rl = a[m:r] + [1e9 + 1] rl a[m:r] + [1e9 + 1] a[m:r] a m:r m r [1e9 + 1] 1e9 + 1 1e9 1 i, j = 0, 0 i 0 j 0 for k in range(l, r):
        if ll[i] < rl[j]:
            a[k] = ll[i]
            i += 1
        else:
            a[k] = rl[j]
            j += 1
        cnt += 1 k range(l, r) range l r if ll[i] < rl[j]:
            a[k] = ll[i]
            i += 1
        else:
            a[k] = rl[j]
            j += 1
         ll[i] < rl[j] ll[i] ll i rl[j] rl j a[k] = ll[i] a[k] a k ll[i] ll i i += 1 i 1 a[k] = rl[j] a[k] a k rl[j] rl j j += 1 j 1 cnt += 1 cnt 1 a a l l m m r r def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r) merge_sort if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r) l + 1 < r l + 1 l 1 r m = (l + r) // 2 m (l + r) // 2 l + r l r 2 merge_sort(a, l, m) merge_sort a l m merge_sort(a, m, r) merge_sort a m r merge(a, l, m, r) merge a l m r a a l l r r n, a, cnt = int(input()), list(map(int, input().split())), 0 n int(input()) int input() input a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cnt 0 merge_sort(a, 0, n) merge_sort a 0 n print(*a) print *a a print(cnt) print cnt def merge(a, l, m, r):
    global cnt
    ll = a[l:m] + [1e9 + 1]
    rl = a[m:r] + [1e9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if ll[i] < rl[j]:
            a[k] = ll[i]
            i += 1
        else:
            a[k] = rl[j]
            j += 1
        cnt += 1 def merge(a, l, m, r):
    global cnt
    ll = a[l:m] + [1e9 + 1]
    rl = a[m:r] + [1e9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if ll[i] < rl[j]:
            a[k] = ll[i]
            i += 1
        else:
            a[k] = rl[j]
            j += 1
        cnt += 1 merge n, a, cnt = int(input()), list(map(int, input().split())), 0 int(input()) n cnt = int(input()), list(map(int, input().split())), 0 0 cnt def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r) def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r) merge_sort a, cnt = int(input()), list(map(int, input().split())), 0 list(map(int, input().split())) a
def merge(a, l, m, r):
    global cnt
    ll = a[l:m] + [1e9 + 1]
    rl = a[m:r] + [1e9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if ll[i] < rl[j]:
            a[k] = ll[i]
            i += 1
        else:
            a[k] = rl[j]
            j += 1
        cnt += 1


def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r)


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