# coding: utf-8
# マージソート
INFTY = int(1E20)
count = 0


def merge(A, left, mid, right):
    global INFTY
    global count

    L = [i for i in A[left:mid]]
    R = [i for i in A[mid:right]]

    L.append(INFTY)
    R.append(INFTY)

    idx_L = 0
    idx_R = 0
    for idx in range(left, right):
        count += 1
        if L[idx_L] <= R[idx_R]:
            A[idx] = L[idx_L]
            idx_L += 1
        else:
            A[idx] = R[idx_R]
            idx_R += 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)
    else:
        return


if __name__ == "__main__":
    n = int(input())
    A = [int(i) for i in input().split()]

    mergeSort(A, 0, n)

    print(' '.join([str(i) for i in A]))

    print(count)
 INFTY = int(1E20) INFTY int(1E20) int 1E20 count = 0 count 0 def merge(A, left, mid, right):
    global INFTY
    global count

    L = [i for i in A[left:mid]]
    R = [i for i in A[mid:right]]

    L.append(INFTY)
    R.append(INFTY)

    idx_L = 0
    idx_R = 0
    for idx in range(left, right):
        count += 1
        if L[idx_L] <= R[idx_R]:
            A[idx] = L[idx_L]
            idx_L += 1
        else:
            A[idx] = R[idx_R]
            idx_R += 1 merge global INFTY global count i for i in A[left:mid] for i in A[left:mid] i A[left:mid] A left:mid left mid for i in A[left:mid] i L = [i for i in A[left:mid]] L [i for i in A[left:mid]] i for i in A[mid:right] for i in A[mid:right] i A[mid:right] A mid:right mid right for i in A[mid:right] i R = [i for i in A[mid:right]] R [i for i in A[mid:right]] L.append(INFTY) L.append L append INFTY R.append(INFTY) R.append R append INFTY idx_L = 0 idx_L 0 idx_R = 0 idx_R 0 for idx in range(left, right):
        count += 1
        if L[idx_L] <= R[idx_R]:
            A[idx] = L[idx_L]
            idx_L += 1
        else:
            A[idx] = R[idx_R]
            idx_R += 1 idx range(left, right) range left right count += 1 count 1 if L[idx_L] <= R[idx_R]:
            A[idx] = L[idx_L]
            idx_L += 1
        else:
            A[idx] = R[idx_R]
            idx_R += 1 L[idx_L] <= R[idx_R] L[idx_L] L idx_L R[idx_R] R idx_R A[idx] = L[idx_L] A[idx] A idx L[idx_L] L idx_L idx_L += 1 idx_L 1 A[idx] = R[idx_R] A[idx] A idx R[idx_R] R idx_R idx_R += 1 idx_R 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)
    else:
        return mergeSort if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
    else:
        return 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 return A A left left right right if __name__ == "__main__":
    n = int(input())
    A = [int(i) for i in input().split()]

    mergeSort(A, 0, n)

    print(' '.join([str(i) for i in A]))

    print(count) __name__ == "__main__" __name__ "__main__" n = int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i A = [int(i) for i in input().split()] A [int(i) for i in input().split()] mergeSort(A, 0, n) mergeSort A 0 n str(i) for i in A for i in A i A for i in A str(i) str i print(' '.join([str(i) for i in A])) print ' '.join([str(i) for i in A]) ' '.join ' ' join [str(i) for i in A] print(count) print count A = [int(i) for i in input().split()] [int(i) for i in input().split()] A 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)
    else:
        return 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)
    else:
        return mergeSort def merge(A, left, mid, right):
    global INFTY
    global count

    L = [i for i in A[left:mid]]
    R = [i for i in A[mid:right]]

    L.append(INFTY)
    R.append(INFTY)

    idx_L = 0
    idx_R = 0
    for idx in range(left, right):
        count += 1
        if L[idx_L] <= R[idx_R]:
            A[idx] = L[idx_L]
            idx_L += 1
        else:
            A[idx] = R[idx_R]
            idx_R += 1 def merge(A, left, mid, right):
    global INFTY
    global count

    L = [i for i in A[left:mid]]
    R = [i for i in A[mid:right]]

    L.append(INFTY)
    R.append(INFTY)

    idx_L = 0
    idx_R = 0
    for idx in range(left, right):
        count += 1
        if L[idx_L] <= R[idx_R]:
            A[idx] = L[idx_L]
            idx_L += 1
        else:
            A[idx] = R[idx_R]
            idx_R += 1 merge INFTY = int(1E20) int(1E20) INFTY count = 0 0 count n = int(input()) int(input()) n
# coding: utf-8
# マージソート
INFTY = int(1E20)
count = 0


def merge(A, left, mid, right):
    global INFTY
    global count

    L = [i for i in A[left:mid]]
    R = [i for i in A[mid:right]]

    L.append(INFTY)
    R.append(INFTY)

    idx_L = 0
    idx_R = 0
    for idx in range(left, right):
        count += 1
        if L[idx_L] <= R[idx_R]:
            A[idx] = L[idx_L]
            idx_L += 1
        else:
            A[idx] = R[idx_R]
            idx_R += 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)
    else:
        return


if __name__ == "__main__":
    n = int(input())
    A = [int(i) for i in input().split()]

    mergeSort(A, 0, n)

    print(' '.join([str(i) for i in A]))

    print(count)

