
def merge(A, n, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]

    L.append(2000000000)  # これをしないとマージするとき、最後の１回でリスト外アクセスでエラー。
    R.append(2000000000)

    global count
    i, j = 0, 0

    # print('left, mid, right')
    # print(left, mid, right)

    for k in range(left, right, 1):
        count += 1
        # print('i, j, k')
        # print(i, j, k)

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

        # print('loop end')


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


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

merge_sort(A, N, 0, N)

print(' '.join(map(str, A)))
print(count)
 def merge(A, n, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]

    L.append(2000000000)  # これをしないとマージするとき、最後の１回でリスト外アクセスでエラー。
    R.append(2000000000)

    global count
    i, j = 0, 0

    # print('left, mid, right')
    # print(left, mid, right)

    for k in range(left, right, 1):
        count += 1
        # print('i, j, k')
        # print(i, j, k)

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

        # print('loop end') 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(2000000000) L.append L append 2000000000 R.append(2000000000) R.append R append 2000000000 global count i, j = 0, 0 i 0 j 0 for k in range(left, right, 1):
        count += 1
        # print('i, j, k')
        # print(i, j, k)

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

        # print('loop end') k range(left, right, 1) range left right 1 count += 1 count 1 if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

        # print('loop end') 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 def merge_sort(A, n, left, right):
    if right - left > 1:
        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 right - left > 1:
        mid = (left + right) // 2
        merge_sort(A, n, left, mid)
        merge_sort(A, n, mid, right)
        merge(A, n, left, mid, right) right - left > 1 right - left right left 1 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 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 merge_sort(A, N, 0, N) merge_sort A N 0 N print(' '.join(map(str, A))) print ' '.join(map(str, A)) ' '.join ' ' join map(str, A) map str A print(count) print count def merge(A, n, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]

    L.append(2000000000)  # これをしないとマージするとき、最後の１回でリスト外アクセスでエラー。
    R.append(2000000000)

    global count
    i, j = 0, 0

    # print('left, mid, right')
    # print(left, mid, right)

    for k in range(left, right, 1):
        count += 1
        # print('i, j, k')
        # print(i, j, k)

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

        # print('loop end') def merge(A, n, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]

    L.append(2000000000)  # これをしないとマージするとき、最後の１回でリスト外アクセスでエラー。
    R.append(2000000000)

    global count
    i, j = 0, 0

    # print('left, mid, right')
    # print(left, mid, right)

    for k in range(left, right, 1):
        count += 1
        # print('i, j, k')
        # print(i, j, k)

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

        # print('loop end') merge count = 0 0 count def merge_sort(A, n, left, right):
    if right - left > 1:
        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 right - left > 1:
        mid = (left + right) // 2
        merge_sort(A, n, left, mid)
        merge_sort(A, n, mid, right)
        merge(A, n, left, mid, right) merge_sort N = int(input()) int(input()) N A = list(map(int, input().split())) list(map(int, input().split())) A

def merge(A, n, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]

    L.append(2000000000)  # これをしないとマージするとき、最後の１回でリスト外アクセスでエラー。
    R.append(2000000000)

    global count
    i, j = 0, 0

    # print('left, mid, right')
    # print(left, mid, right)

    for k in range(left, right, 1):
        count += 1
        # print('i, j, k')
        # print(i, j, k)

        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

        # print('loop end')


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


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

merge_sort(A, N, 0, N)

print(' '.join(map(str, A)))
print(count)

