import sys
n = int(input())
sort_list = list(map(int,input().split()))

cnt = []
def merge(A, left,mid,right):
    n1 = mid -left
    n2 = right - mid
    L = [i for i in A[left : left + n1]]
    R = [i for i in A[mid : mid + n2]]
    L.append(sys.maxsize)
    R.append(sys.maxsize)

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

    cnt.append(c)

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

mergesort(sort_list, 0, len(sort_list))
print(' '.join([str(i) for i in sort_list]))
print(sum(cnt))
 import sys sys n = int(input()) n int(input()) int input() input sort_list = list(map(int,input().split())) sort_list list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split cnt = [] cnt [] def merge(A, left,mid,right):
    n1 = mid -left
    n2 = right - mid
    L = [i for i in A[left : left + n1]]
    R = [i for i in A[mid : mid + n2]]
    L.append(sys.maxsize)
    R.append(sys.maxsize)

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

    cnt.append(c) merge n1 = mid -left n1 mid -left mid left n2 = right - mid n2 right - mid right mid i for i in A[left : left + n1] for i in A[left : left + n1] i A[left : left + n1] A left : left + n1 left left + n1 left n1 for i in A[left : left + n1] i L = [i for i in A[left : left + n1]] L [i for i in A[left : left + n1]] i for i in A[mid : mid + n2] for i in A[mid : mid + n2] i A[mid : mid + n2] A mid : mid + n2 mid mid + n2 mid n2 for i in A[mid : mid + n2] i R = [i for i in A[mid : mid + n2]] R [i for i in A[mid : mid + n2]] L.append(sys.maxsize) L.append L append sys.maxsize sys maxsize R.append(sys.maxsize) R.append R append sys.maxsize sys maxsize i = 0 i 0 j = 0 j 0 c = 0 c 0 for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
        c += 1

     k range(left,right) range left right if L[i] <= R[j]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            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 = i + 1 i i + 1 i 1 A[k] = R[j] A[k] A k R[j] R j j = j + 1 j j + 1 j 1 c += 1 c 1 cnt.append(c) cnt.append cnt append c A A left left mid mid right right def mergesort(A,left,right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right) mergesort if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right) left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 mergesort(A,left,mid) mergesort A left mid mergesort(A,mid,right) mergesort A mid right merge(A,left,mid,right) merge A left mid right A A left left right right mergesort(sort_list, 0, len(sort_list)) mergesort sort_list 0 len(sort_list) len sort_list str(i) for i in sort_list for i in sort_list i sort_list for i in sort_list str(i) str i print(' '.join([str(i) for i in sort_list])) print ' '.join([str(i) for i in sort_list]) ' '.join ' ' join [str(i) for i in sort_list] print(sum(cnt)) print sum(cnt) sum cnt sort_list = list(map(int,input().split())) list(map(int,input().split())) sort_list def merge(A, left,mid,right):
    n1 = mid -left
    n2 = right - mid
    L = [i for i in A[left : left + n1]]
    R = [i for i in A[mid : mid + n2]]
    L.append(sys.maxsize)
    R.append(sys.maxsize)

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

    cnt.append(c) def merge(A, left,mid,right):
    n1 = mid -left
    n2 = right - mid
    L = [i for i in A[left : left + n1]]
    R = [i for i in A[mid : mid + n2]]
    L.append(sys.maxsize)
    R.append(sys.maxsize)

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

    cnt.append(c) merge cnt = [] [] cnt n = int(input()) int(input()) n def mergesort(A,left,right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right) def mergesort(A,left,right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right) mergesort
import sys
n = int(input())
sort_list = list(map(int,input().split()))

cnt = []
def merge(A, left,mid,right):
    n1 = mid -left
    n2 = right - mid
    L = [i for i in A[left : left + n1]]
    R = [i for i in A[mid : mid + n2]]
    L.append(sys.maxsize)
    R.append(sys.maxsize)

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

    cnt.append(c)

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

mergesort(sort_list, 0, len(sort_list))
print(' '.join([str(i) for i in sort_list]))
print(sum(cnt))

