def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = 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
    return right-left


def merge_sort(A, left, right):
    if left+1 < right:
        mid = (left+right)//2
        ans1 = merge_sort(A, left, mid)
        ans2 = merge_sort(A, mid, right)
        return merge(A, left, mid, right)+ans1+ans2
    return 0


N = int(input())
S = list(map(int, input().split()))
ans = merge_sort(S, 0, N)
print(*S)
print(ans)
 def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = 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
    return right-left merge L = A[left:mid] L A[left:mid] A left:mid left mid R = A[mid:right] R A[mid:right] A mid:right mid right L.append(10**9+1) L.append L append 10**9+1 10**9 10 9 1 R.append(10**9+1) R.append R append 10**9+1 10**9 10 9 1 i = 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 return right-left 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
        ans1 = merge_sort(A, left, mid)
        ans2 = merge_sort(A, mid, right)
        return merge(A, left, mid, right)+ans1+ans2
    return 0 merge_sort if left+1 < right:
        mid = (left+right)//2
        ans1 = merge_sort(A, left, mid)
        ans2 = merge_sort(A, mid, right)
        return merge(A, left, mid, right)+ans1+ans2
     left+1 < right left+1 left 1 right mid = (left+right)//2 mid (left+right)//2 left+right left right 2 ans1 = merge_sort(A, left, mid) ans1 merge_sort(A, left, mid) merge_sort A left mid ans2 = merge_sort(A, mid, right) ans2 merge_sort(A, mid, right) merge_sort A mid right return merge(A, left, mid, right)+ans1+ans2 merge(A, left, mid, right)+ans1+ans2 merge(A, left, mid, right)+ans1 merge(A, left, mid, right) merge A left mid right ans1 ans2 return 0 0 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 ans = merge_sort(S, 0, N) ans merge_sort(S, 0, N) merge_sort S 0 N print(*S) print *S S print(ans) print ans S = list(map(int, input().split())) list(map(int, input().split())) S ans = merge_sort(S, 0, N) merge_sort(S, 0, N) ans N = int(input()) int(input()) N def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = 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
    return right-left def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = 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
    return right-left merge def merge_sort(A, left, right):
    if left+1 < right:
        mid = (left+right)//2
        ans1 = merge_sort(A, left, mid)
        ans2 = merge_sort(A, mid, right)
        return merge(A, left, mid, right)+ans1+ans2
    return 0 def merge_sort(A, left, right):
    if left+1 < right:
        mid = (left+right)//2
        ans1 = merge_sort(A, left, mid)
        ans2 = merge_sort(A, mid, right)
        return merge(A, left, mid, right)+ans1+ans2
    return 0 merge_sort
def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    L.append(10**9+1)
    R.append(10**9+1)
    i = 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
    return right-left


def merge_sort(A, left, right):
    if left+1 < right:
        mid = (left+right)//2
        ans1 = merge_sort(A, left, mid)
        ans2 = merge_sort(A, mid, right)
        return merge(A, left, mid, right)+ans1+ans2
    return 0


N = int(input())
S = list(map(int, input().split()))
ans = merge_sort(S, 0, N)
print(*S)
print(ans)

