SENTINEL = float('inf')
count = 0


def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    merge_sort(a_s, n, 0, n)
    print(' '.join(map(str, a_s)))
    print(count)


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


def merge(A, n, left, mid, right):
    global count
    L = A[left:mid]
    R = A[mid:right]
    L.append(SENTINEL)
    R.append(SENTINEL)
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


if __name__ == "__main__":
    main()
 SENTINEL = float('inf') SENTINEL float('inf') float 'inf' count = 0 count 0 def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    merge_sort(a_s, n, 0, n)
    print(' '.join(map(str, a_s)))
    print(count) main n = int(input()) n int(input()) int input() input a_s = list(map(int, input().split(' '))) a_s list(map(int, input().split(' '))) list map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' merge_sort(a_s, n, 0, n) merge_sort a_s n 0 n print(' '.join(map(str, a_s))) print ' '.join(map(str, a_s)) ' '.join ' ' join map(str, a_s) map str a_s print(count) print count def merge_sort(A, n, left, right):
    if left+1 < right:
        mid = (left+right) // 2
        merge_sort(A, n, left, mid)
        merge_sort(A, n, mid, right)
        merge(A, n, left, mid, right) merge_sort if left+1 < right:
        mid = (left+right) // 2
        merge_sort(A, n, left, mid)
        merge_sort(A, n, mid, right)
        merge(A, n, left, mid, right) left+1 < right left+1 left 1 right mid = (left+right) // 2 mid (left+right) // 2 left+right left right 2 merge_sort(A, n, left, mid) merge_sort A n left mid merge_sort(A, n, mid, right) merge_sort A n mid right merge(A, n, left, mid, right) merge A n left mid right A A n n left left right right def merge(A, n, left, mid, right):
    global count
    L = A[left:mid]
    R = A[mid:right]
    L.append(SENTINEL)
    R.append(SENTINEL)
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 merge global count 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(SENTINEL) L.append L append SENTINEL R.append(SENTINEL) R.append R append SENTINEL i = j = 0 i 0 = j = 0 j 0 for k in range(left, right):
        count += 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 count += 1 count 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 n n left left mid mid right right if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main count = 0 0 count def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    merge_sort(a_s, n, 0, n)
    print(' '.join(map(str, a_s)))
    print(count) def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    merge_sort(a_s, n, 0, n)
    print(' '.join(map(str, a_s)))
    print(count) main def merge(A, n, left, mid, right):
    global count
    L = A[left:mid]
    R = A[mid:right]
    L.append(SENTINEL)
    R.append(SENTINEL)
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 def merge(A, n, left, mid, right):
    global count
    L = A[left:mid]
    R = A[mid:right]
    L.append(SENTINEL)
    R.append(SENTINEL)
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 merge SENTINEL = float('inf') float('inf') SENTINEL def merge_sort(A, n, left, right):
    if left+1 < right:
        mid = (left+right) // 2
        merge_sort(A, n, left, mid)
        merge_sort(A, n, mid, right)
        merge(A, n, left, mid, right) def merge_sort(A, n, left, right):
    if left+1 < right:
        mid = (left+right) // 2
        merge_sort(A, n, left, mid)
        merge_sort(A, n, mid, right)
        merge(A, n, left, mid, right) merge_sort
SENTINEL = float('inf')
count = 0


def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    merge_sort(a_s, n, 0, n)
    print(' '.join(map(str, a_s)))
    print(count)


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


def merge(A, n, left, mid, right):
    global count
    L = A[left:mid]
    R = A[mid:right]
    L.append(SENTINEL)
    R.append(SENTINEL)
    i = j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


if __name__ == "__main__":
    main()

