count = 0

def Merge(arr, left, mid, right):

    global count

    inf = 10000000000
    n1 = mid - left
    n2 = right - mid
    L = arr[left:left + n1] + [inf]
    R = arr[mid:mid + n2] + [inf]

    i = j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
            count += 1      
        else:
            arr[k] = R[j]
            j += 1
            count += 1
            
def MergeSort(arr, left, right):
    if (left + 1) < right:
        mid = int((left + right)/2)
        MergeSort(arr, left, mid)
        MergeSort(arr, mid, right)
        Merge(arr, left, mid, right)

def Main():
    n = int(input())
    arr = [int(a) for a in input().split()]

    MergeSort(arr, 0, n)

    print(*arr)
    print(count)

Main() count = 0 count 0 def Merge(arr, left, mid, right):

    global count

    inf = 10000000000
    n1 = mid - left
    n2 = right - mid
    L = arr[left:left + n1] + [inf]
    R = arr[mid:mid + n2] + [inf]

    i = j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
            count += 1      
        else:
            arr[k] = R[j]
            j += 1
            count += 1
             Merge global count inf = 10000000000 inf 10000000000 n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = arr[left:left + n1] + [inf] L arr[left:left + n1] + [inf] arr[left:left + n1] arr left:left + n1 left left + n1 left n1 [inf] inf R = arr[mid:mid + n2] + [inf] R arr[mid:mid + n2] + [inf] arr[mid:mid + n2] arr mid:mid + n2 mid mid + n2 mid n2 [inf] inf i = j = 0 i 0 = j = 0 j 0 for k in range(left, right):
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
            count += 1      
        else:
            arr[k] = R[j]
            j += 1
            count += 1
             k range(left, right) range left right if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
            count += 1      
        else:
            arr[k] = R[j]
            j += 1
            count += 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 count += 1 count 1 arr[k] = R[j] arr[k] arr k R[j] R j j += 1 j 1 count += 1 count 1 arr arr left left mid mid right right def MergeSort(arr, left, right):
    if (left + 1) < right:
        mid = int((left + right)/2)
        MergeSort(arr, left, mid)
        MergeSort(arr, mid, right)
        Merge(arr, left, mid, right) MergeSort if (left + 1) < right:
        mid = int((left + right)/2)
        MergeSort(arr, left, mid)
        MergeSort(arr, mid, right)
        Merge(arr, left, mid, right) (left + 1) < right left + 1 left 1 right mid = int((left + right)/2) mid int((left + right)/2) int (left + right)/2 left + right left right 2 MergeSort(arr, left, mid) MergeSort arr left mid MergeSort(arr, mid, right) MergeSort arr mid right Merge(arr, left, mid, right) Merge arr left mid right arr arr left left right right def Main():
    n = int(input())
    arr = [int(a) for a in input().split()]

    MergeSort(arr, 0, n)

    print(*arr)
    print(count) Main n = int(input()) n int(input()) int input() input int(a) for a in input().split() for a in input().split() a input().split() ().split () input split for a in input().split() int(a) int a arr = [int(a) for a in input().split()] arr [int(a) for a in input().split()] MergeSort(arr, 0, n) MergeSort arr 0 n print(*arr) print *arr arr print(count) print count Main() Main def Merge(arr, left, mid, right):

    global count

    inf = 10000000000
    n1 = mid - left
    n2 = right - mid
    L = arr[left:left + n1] + [inf]
    R = arr[mid:mid + n2] + [inf]

    i = j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
            count += 1      
        else:
            arr[k] = R[j]
            j += 1
            count += 1
             def Merge(arr, left, mid, right):

    global count

    inf = 10000000000
    n1 = mid - left
    n2 = right - mid
    L = arr[left:left + n1] + [inf]
    R = arr[mid:mid + n2] + [inf]

    i = j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
            count += 1      
        else:
            arr[k] = R[j]
            j += 1
            count += 1
             Merge def MergeSort(arr, left, right):
    if (left + 1) < right:
        mid = int((left + right)/2)
        MergeSort(arr, left, mid)
        MergeSort(arr, mid, right)
        Merge(arr, left, mid, right) def MergeSort(arr, left, right):
    if (left + 1) < right:
        mid = int((left + right)/2)
        MergeSort(arr, left, mid)
        MergeSort(arr, mid, right)
        Merge(arr, left, mid, right) MergeSort count = 0 0 count def Main():
    n = int(input())
    arr = [int(a) for a in input().split()]

    MergeSort(arr, 0, n)

    print(*arr)
    print(count) def Main():
    n = int(input())
    arr = [int(a) for a in input().split()]

    MergeSort(arr, 0, n)

    print(*arr)
    print(count) Main
count = 0

def Merge(arr, left, mid, right):

    global count

    inf = 10000000000
    n1 = mid - left
    n2 = right - mid
    L = arr[left:left + n1] + [inf]
    R = arr[mid:mid + n2] + [inf]

    i = j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
            count += 1      
        else:
            arr[k] = R[j]
            j += 1
            count += 1
            
def MergeSort(arr, left, right):
    if (left + 1) < right:
        mid = int((left + right)/2)
        MergeSort(arr, left, mid)
        MergeSort(arr, mid, right)
        Merge(arr, left, mid, right)

def Main():
    n = int(input())
    arr = [int(a) for a in input().split()]

    MergeSort(arr, 0, n)

    print(*arr)
    print(count)

Main()
