def mergeSort(A, left, right, n):
    if left + 1 < right:
        mid = int((right + left ) / 2 )
        mergeSort(A, left, mid, n)
        mergeSort(A, mid, right, n)
        return (merge(A, left, mid, right, n))

def merge(A, left, mid, right, n):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]  + [10 ** 9 + 1]
    R = A[mid:right] + [10 ** 9 + 1]
    i , j = 0, 0
    for k in range(left, right):
        A[n] += 1
        if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
    return A

n = int(input())
A = list(map(int, input().split()))
A.append(0)
S = mergeSort(A, 0, len(A) - 1, n)
print(" ".join(list(map(str, S[:n]))))
print(S[n]) def mergeSort(A, left, right, n):
    if left + 1 < right:
        mid = int((right + left ) / 2 )
        mergeSort(A, left, mid, n)
        mergeSort(A, mid, right, n)
        return (merge(A, left, mid, right, n)) mergeSort if left + 1 < right:
        mid = int((right + left ) / 2 )
        mergeSort(A, left, mid, n)
        mergeSort(A, mid, right, n)
        return (merge(A, left, mid, right, n)) left + 1 < right left + 1 left 1 right mid = int((right + left ) / 2 ) mid int((right + left ) / 2 ) int (right + left ) / 2 right + left right left 2 mergeSort(A, left, mid, n) mergeSort A left mid n mergeSort(A, mid, right, n) mergeSort A mid right n return (merge(A, left, mid, right, n)) merge(A, left, mid, right, n) merge A left mid right n A A left left right right n n def merge(A, left, mid, right, n):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]  + [10 ** 9 + 1]
    R = A[mid:right] + [10 ** 9 + 1]
    i , j = 0, 0
    for k in range(left, right):
        A[n] += 1
        if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
    return A merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid 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 , j = 0, 0 i 0 j 0 for k in range(left, right):
        A[n] += 1
        if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
     k range(left, right) range left right A[n] += 1 A[n] A n 1 if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
     L[i] <= R[j] L[i] L i R[j] R j key = L[i] key L[i] L i A[k] = key A[k] A k key i += 1 i 1 key = R[j] key R[j] R j A[k] = key A[k] A k key j += 1 j 1 return A A A A left left mid mid right right n n 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 A.append(0) A.append A append 0 S = mergeSort(A, 0, len(A) - 1, n) S mergeSort(A, 0, len(A) - 1, n) mergeSort A 0 len(A) - 1 len(A) len A 1 n print(" ".join(list(map(str, S[:n])))) print " ".join(list(map(str, S[:n]))) " ".join " " join list(map(str, S[:n])) list map(str, S[:n]) map str S[:n] S :n n print(S[n]) print S[n] S n A = list(map(int, input().split())) list(map(int, input().split())) A S = mergeSort(A, 0, len(A) - 1, n) mergeSort(A, 0, len(A) - 1, n) S def merge(A, left, mid, right, n):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]  + [10 ** 9 + 1]
    R = A[mid:right] + [10 ** 9 + 1]
    i , j = 0, 0
    for k in range(left, right):
        A[n] += 1
        if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
    return A def merge(A, left, mid, right, n):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]  + [10 ** 9 + 1]
    R = A[mid:right] + [10 ** 9 + 1]
    i , j = 0, 0
    for k in range(left, right):
        A[n] += 1
        if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
    return A merge n = int(input()) int(input()) n def mergeSort(A, left, right, n):
    if left + 1 < right:
        mid = int((right + left ) / 2 )
        mergeSort(A, left, mid, n)
        mergeSort(A, mid, right, n)
        return (merge(A, left, mid, right, n)) def mergeSort(A, left, right, n):
    if left + 1 < right:
        mid = int((right + left ) / 2 )
        mergeSort(A, left, mid, n)
        mergeSort(A, mid, right, n)
        return (merge(A, left, mid, right, n)) mergeSort
def mergeSort(A, left, right, n):
    if left + 1 < right:
        mid = int((right + left ) / 2 )
        mergeSort(A, left, mid, n)
        mergeSort(A, mid, right, n)
        return (merge(A, left, mid, right, n))

def merge(A, left, mid, right, n):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]  + [10 ** 9 + 1]
    R = A[mid:right] + [10 ** 9 + 1]
    i , j = 0, 0
    for k in range(left, right):
        A[n] += 1
        if L[i] <= R[j]:
            key = L[i]
            A[k] = key
            i += 1
        else:
            key = R[j]
            A[k] = key
            j += 1
    return A

n = int(input())
A = list(map(int, input().split()))
A.append(0)
S = mergeSort(A, 0, len(A) - 1, n)
print(" ".join(list(map(str, S[:n]))))
print(S[n])
