
cnt = 0
SENTINEL = 2000000000

def merge(arr, length, left, mid, right):
#  n1 = mid - left
#  n2 = right - mid

    L = arr[left : mid]
    R = arr[mid : right]

    L.append(SENTINEL)
    R.append(SENTINEL)

    i, j = 0, 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if (L[i] <= R[j]):
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1

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

if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))

    merge_sort(S, n, 0, n)
    print(' '.join(map(str, S)))
    print(cnt)
 cnt = 0 cnt 0 SENTINEL = 2000000000 SENTINEL 2000000000 def merge(arr, length, left, mid, right):
#  n1 = mid - left
#  n2 = right - mid

    L = arr[left : mid]
    R = arr[mid : right]

    L.append(SENTINEL)
    R.append(SENTINEL)

    i, j = 0, 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if (L[i] <= R[j]):
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1 merge L = arr[left : mid] L arr[left : mid] arr left : mid left mid R = arr[mid : right] R arr[mid : right] arr mid : right mid right L.append(SENTINEL) L.append L append SENTINEL R.append(SENTINEL) R.append R append SENTINEL i, j = 0, 0 i 0 j 0 for k in range(left, right):
        global cnt
        cnt += 1
        if (L[i] <= R[j]):
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1 k range(left, right) range left right global cnt cnt += 1 cnt 1 if (L[i] <= R[j]):
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1 L[i] <= R[j] L[i] L i R[j] R j arr[k] = L[i] arr[k] arr k L[i] L i i += 1 i 1 arr[k] = R[j] arr[k] arr k R[j] R j j += 1 j 1 arr arr length length left left mid mid right right def merge_sort(arr, length, left, right):
    if (left + 1 < right):
        mid = (left + right)//2
        merge_sort(arr, length, left, mid)
        merge_sort(arr, length, mid, right)
        merge(arr, n, left, mid, right)     merge_sort if (left + 1 < right):
        mid = (left + right)//2
        merge_sort(arr, length, left, mid)
        merge_sort(arr, length, mid, right)
        merge(arr, 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(arr, length, left, mid) merge_sort arr length left mid merge_sort(arr, length, mid, right) merge_sort arr length mid right merge(arr, n, left, mid, right) merge arr n left mid right arr arr length length left left right right if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))

    merge_sort(S, n, 0, n)
    print(' '.join(map(str, S)))
    print(cnt) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split merge_sort(S, n, 0, n) merge_sort S n 0 n print(' '.join(map(str, S))) print ' '.join(map(str, S)) ' '.join ' ' join map(str, S) map str S print(cnt) print cnt def merge_sort(arr, length, left, right):
    if (left + 1 < right):
        mid = (left + right)//2
        merge_sort(arr, length, left, mid)
        merge_sort(arr, length, mid, right)
        merge(arr, n, left, mid, right)     def merge_sort(arr, length, left, right):
    if (left + 1 < right):
        mid = (left + right)//2
        merge_sort(arr, length, left, mid)
        merge_sort(arr, length, mid, right)
        merge(arr, n, left, mid, right)     merge_sort def merge(arr, length, left, mid, right):
#  n1 = mid - left
#  n2 = right - mid

    L = arr[left : mid]
    R = arr[mid : right]

    L.append(SENTINEL)
    R.append(SENTINEL)

    i, j = 0, 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if (L[i] <= R[j]):
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1 def merge(arr, length, left, mid, right):
#  n1 = mid - left
#  n2 = right - mid

    L = arr[left : mid]
    R = arr[mid : right]

    L.append(SENTINEL)
    R.append(SENTINEL)

    i, j = 0, 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if (L[i] <= R[j]):
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1 merge n = int(input()) int(input()) n cnt = 0 0 cnt SENTINEL = 2000000000 2000000000 SENTINEL S = list(map(int, input().split())) list(map(int, input().split())) S

cnt = 0
SENTINEL = 2000000000

def merge(arr, length, left, mid, right):
#  n1 = mid - left
#  n2 = right - mid

    L = arr[left : mid]
    R = arr[mid : right]

    L.append(SENTINEL)
    R.append(SENTINEL)

    i, j = 0, 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if (L[i] <= R[j]):
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1

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

if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))

    merge_sort(S, n, 0, n)
    print(' '.join(map(str, S)))
    print(cnt)

