num = int(input())
arr = list(map(int, input().split()))

def merge(arr, left, middle, right, count):
    L = arr[left:middle]
    L.append(float('inf'))
    R = arr[middle:right]
    R.append(float('inf'))

    iterL, iterR = iter(L), iter(R)
    l,r = next(iterL), next(iterR)

    for index in range(left, right):
        count += 1
        if l <= r:
            arr[index] = l
            l = next(iterL)
        else:
            arr[index] = r
            r = next(iterR)
    return count

def merge_sort(arr, left, right, count):

    if left + 1 < right:
        pivot = (left + right) // 2
        count = merge_sort(arr, left,  pivot, count)
        count = merge_sort(arr, pivot, right, count)

        count = merge(arr, left, pivot, right, count)
    return count

count = merge_sort(arr, 0, num, 0)
print(" ".join(list(map(str, arr))))
print(count) num = int(input()) num int(input()) int input() input arr = list(map(int, input().split())) arr list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def merge(arr, left, middle, right, count):
    L = arr[left:middle]
    L.append(float('inf'))
    R = arr[middle:right]
    R.append(float('inf'))

    iterL, iterR = iter(L), iter(R)
    l,r = next(iterL), next(iterR)

    for index in range(left, right):
        count += 1
        if l <= r:
            arr[index] = l
            l = next(iterL)
        else:
            arr[index] = r
            r = next(iterR)
    return count merge L = arr[left:middle] L arr[left:middle] arr left:middle left middle L.append(float('inf')) L.append L append float('inf') float 'inf' R = arr[middle:right] R arr[middle:right] arr middle:right middle right R.append(float('inf')) R.append R append float('inf') float 'inf' iterL, iterR = iter(L), iter(R) iterL iter(L) iter L iterR iter(R) iter R l,r = next(iterL), next(iterR) l next(iterL) next iterL r next(iterR) next iterR for index in range(left, right):
        count += 1
        if l <= r:
            arr[index] = l
            l = next(iterL)
        else:
            arr[index] = r
            r = next(iterR)
     index range(left, right) range left right count += 1 count 1 if l <= r:
            arr[index] = l
            l = next(iterL)
        else:
            arr[index] = r
            r = next(iterR)
     l <= r l r arr[index] = l arr[index] arr index l l = next(iterL) l next(iterL) next iterL arr[index] = r arr[index] arr index r r = next(iterR) r next(iterR) next iterR return count count arr arr left left middle middle right right count count def merge_sort(arr, left, right, count):

    if left + 1 < right:
        pivot = (left + right) // 2
        count = merge_sort(arr, left,  pivot, count)
        count = merge_sort(arr, pivot, right, count)

        count = merge(arr, left, pivot, right, count)
    return count merge_sort if left + 1 < right:
        pivot = (left + right) // 2
        count = merge_sort(arr, left,  pivot, count)
        count = merge_sort(arr, pivot, right, count)

        count = merge(arr, left, pivot, right, count)
     left + 1 < right left + 1 left 1 right pivot = (left + right) // 2 pivot (left + right) // 2 left + right left right 2 count = merge_sort(arr, left,  pivot, count) count merge_sort(arr, left,  pivot, count) merge_sort arr left pivot count count = merge_sort(arr, pivot, right, count) count merge_sort(arr, pivot, right, count) merge_sort arr pivot right count count = merge(arr, left, pivot, right, count) count merge(arr, left, pivot, right, count) merge arr left pivot right count return count count arr arr left left right right count count count = merge_sort(arr, 0, num, 0) count merge_sort(arr, 0, num, 0) merge_sort arr 0 num 0 print(" ".join(list(map(str, arr)))) print " ".join(list(map(str, arr))) " ".join " " join list(map(str, arr)) list map(str, arr) map str arr print(count) print count def merge_sort(arr, left, right, count):

    if left + 1 < right:
        pivot = (left + right) // 2
        count = merge_sort(arr, left,  pivot, count)
        count = merge_sort(arr, pivot, right, count)

        count = merge(arr, left, pivot, right, count)
    return count def merge_sort(arr, left, right, count):

    if left + 1 < right:
        pivot = (left + right) // 2
        count = merge_sort(arr, left,  pivot, count)
        count = merge_sort(arr, pivot, right, count)

        count = merge(arr, left, pivot, right, count)
    return count merge_sort count = merge_sort(arr, 0, num, 0) merge_sort(arr, 0, num, 0) count num = int(input()) int(input()) num arr = list(map(int, input().split())) list(map(int, input().split())) arr def merge(arr, left, middle, right, count):
    L = arr[left:middle]
    L.append(float('inf'))
    R = arr[middle:right]
    R.append(float('inf'))

    iterL, iterR = iter(L), iter(R)
    l,r = next(iterL), next(iterR)

    for index in range(left, right):
        count += 1
        if l <= r:
            arr[index] = l
            l = next(iterL)
        else:
            arr[index] = r
            r = next(iterR)
    return count def merge(arr, left, middle, right, count):
    L = arr[left:middle]
    L.append(float('inf'))
    R = arr[middle:right]
    R.append(float('inf'))

    iterL, iterR = iter(L), iter(R)
    l,r = next(iterL), next(iterR)

    for index in range(left, right):
        count += 1
        if l <= r:
            arr[index] = l
            l = next(iterL)
        else:
            arr[index] = r
            r = next(iterR)
    return count merge
num = int(input())
arr = list(map(int, input().split()))

def merge(arr, left, middle, right, count):
    L = arr[left:middle]
    L.append(float('inf'))
    R = arr[middle:right]
    R.append(float('inf'))

    iterL, iterR = iter(L), iter(R)
    l,r = next(iterL), next(iterR)

    for index in range(left, right):
        count += 1
        if l <= r:
            arr[index] = l
            l = next(iterL)
        else:
            arr[index] = r
            r = next(iterR)
    return count

def merge_sort(arr, left, right, count):

    if left + 1 < right:
        pivot = (left + right) // 2
        count = merge_sort(arr, left,  pivot, count)
        count = merge_sort(arr, pivot, right, count)

        count = merge(arr, left, pivot, right, count)
    return count

count = merge_sort(arr, 0, num, 0)
print(" ".join(list(map(str, arr))))
print(count)
