def merge(a, left, mid, right):
    global cnt
    l = a[left:mid] + [10**9 + 1]
    r = a[mid:right] + [10**9 + 1]

    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1


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


n = int(input())
S = list(map(int, input().split()))
cnt = 0
mergesort(S, 0, n)
print(*S)
print(cnt) def merge(a, left, mid, right):
    global cnt
    l = a[left:mid] + [10**9 + 1]
    r = a[mid:right] + [10**9 + 1]

    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1 merge global cnt l = a[left:mid] + [10**9 + 1] l a[left:mid] + [10**9 + 1] a[left:mid] a left:mid left mid [10**9 + 1] 10**9 + 1 10**9 10 9 1 r = a[mid:right] + [10**9 + 1] r a[mid:right] + [10**9 + 1] a[mid:right] a mid:right mid right [10**9 + 1] 10**9 + 1 10**9 10 9 1 i = 0 i 0 j = 0 j 0 for k in range(left, right):
        cnt += 1
        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 cnt += 1 cnt 1 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 a a left left mid mid right right def mergesort(a, left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergesort(a, left, mid)
        mergesort(a, mid, right)
        merge(a, left, mid, right)
    pass mergesort if left+1 < right:
        mid = (left + right)//2
        mergesort(a, left, mid)
        mergesort(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 mergesort(a, left, mid) mergesort a left mid mergesort(a, mid, right) mergesort a mid right merge(a, left, mid, right) merge a left mid right a a left left right right n = int(input()) n int(input()) int input() input S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cnt = 0 cnt 0 mergesort(S, 0, n) mergesort S 0 n print(*S) print *S S print(cnt) print cnt def mergesort(a, left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergesort(a, left, mid)
        mergesort(a, mid, right)
        merge(a, left, mid, right)
    pass def mergesort(a, left, right):
    if left+1 < right:
        mid = (left + right)//2
        mergesort(a, left, mid)
        mergesort(a, mid, right)
        merge(a, left, mid, right)
    pass mergesort cnt = 0 0 cnt n = int(input()) int(input()) n def merge(a, left, mid, right):
    global cnt
    l = a[left:mid] + [10**9 + 1]
    r = a[mid:right] + [10**9 + 1]

    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1 def merge(a, left, mid, right):
    global cnt
    l = a[left:mid] + [10**9 + 1]
    r = a[mid:right] + [10**9 + 1]

    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1 merge S = list(map(int, input().split())) list(map(int, input().split())) S
def merge(a, left, mid, right):
    global cnt
    l = a[left:mid] + [10**9 + 1]
    r = a[mid:right] + [10**9 + 1]

    i = 0
    j = 0
    for k in range(left, right):
        cnt += 1
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else:
            a[k] = r[j]
            j += 1


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


n = int(input())
S = list(map(int, input().split()))
cnt = 0
mergesort(S, 0, n)
print(*S)
print(cnt)