n = int(input())
A = list(map(int, input().split()))
count = 0


def merge(A, l, m, r):
    L = A[l:m] + [10 ** 9 + 1]
    R = A[m:r] + [10 ** 9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global count
    count += r - l


def mergeSort(A, l, r):
    if r - l > 1:
        m = (l + r) // 2
        mergeSort(A, l, m)
        mergeSort(A, m, r)
        merge(A, l, m, r)


mergeSort(A, 0, n)
print(" ".join(list(map(str, A))))
print(count)
 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 def merge(A, l, m, r):
    L = A[l:m] + [10 ** 9 + 1]
    R = A[m:r] + [10 ** 9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global count
    count += r - l merge L = A[l:m] + [10 ** 9 + 1] L A[l:m] + [10 ** 9 + 1] A[l:m] A l:m l m [10 ** 9 + 1] 10 ** 9 + 1 10 ** 9 10 9 1 R = A[m:r] + [10 ** 9 + 1] R A[m:r] + [10 ** 9 + 1] A[m:r] A m:r m r [10 ** 9 + 1] 10 ** 9 + 1 10 ** 9 10 9 1 i, j = 0, 0 i 0 j 0 for k in range(l, r):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
     k range(l, r) range l r 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 global count count += r - l count r - l r l A A l l m m r r def mergeSort(A, l, r):
    if r - l > 1:
        m = (l + r) // 2
        mergeSort(A, l, m)
        mergeSort(A, m, r)
        merge(A, l, m, r) mergeSort if r - l > 1:
        m = (l + r) // 2
        mergeSort(A, l, m)
        mergeSort(A, m, r)
        merge(A, l, m, r) r - l > 1 r - l r l 1 m = (l + r) // 2 m (l + r) // 2 l + r l r 2 mergeSort(A, l, m) mergeSort A l m mergeSort(A, m, r) mergeSort A m r merge(A, l, m, r) merge A l m r A A l l r r mergeSort(A, 0, n) mergeSort A 0 n print(" ".join(list(map(str, A)))) print " ".join(list(map(str, A))) " ".join " " join list(map(str, A)) list map(str, A) map str A print(count) print count count = 0 0 count n = int(input()) int(input()) n def merge(A, l, m, r):
    L = A[l:m] + [10 ** 9 + 1]
    R = A[m:r] + [10 ** 9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global count
    count += r - l def merge(A, l, m, r):
    L = A[l:m] + [10 ** 9 + 1]
    R = A[m:r] + [10 ** 9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global count
    count += r - l merge A = list(map(int, input().split())) list(map(int, input().split())) A def mergeSort(A, l, r):
    if r - l > 1:
        m = (l + r) // 2
        mergeSort(A, l, m)
        mergeSort(A, m, r)
        merge(A, l, m, r) def mergeSort(A, l, r):
    if r - l > 1:
        m = (l + r) // 2
        mergeSort(A, l, m)
        mergeSort(A, m, r)
        merge(A, l, m, r) mergeSort
n = int(input())
A = list(map(int, input().split()))
count = 0


def merge(A, l, m, r):
    L = A[l:m] + [10 ** 9 + 1]
    R = A[m:r] + [10 ** 9 + 1]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global count
    count += r - l


def mergeSort(A, l, r):
    if r - l > 1:
        m = (l + r) // 2
        mergeSort(A, l, m)
        mergeSort(A, m, r)
        merge(A, l, m, r)


mergeSort(A, 0, n)
print(" ".join(list(map(str, A))))
print(count)

