c = 0

def merge(a,l,m,r):
    global c
    n1 = m-l
    n2 = r-m
    L = a[l:m]
    R = a[m:r]
    L.append(1000000009)
    R.append(1000000009)
    i,j = 0,0
    for k in range(l,r):
        if L[i]<=R[j]:
            a[k] = L[i]
            i += 1
        else :
            a[k] = R[j]
            j += 1
        c+=1

def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r)

def main():
    n = int(input())
    a = list(map(int,input().split()))
    mergeSort(a,0,n)
    print (' '.join(map(str,a)))
    print (c)

if __name__ == '__main__':
    main()

 c = 0 c 0 def merge(a,l,m,r):
    global c
    n1 = m-l
    n2 = r-m
    L = a[l:m]
    R = a[m:r]
    L.append(1000000009)
    R.append(1000000009)
    i,j = 0,0
    for k in range(l,r):
        if L[i]<=R[j]:
            a[k] = L[i]
            i += 1
        else :
            a[k] = R[j]
            j += 1
        c+=1 merge global c n1 = m-l n1 m-l m l n2 = r-m n2 r-m r m L = a[l:m] L a[l:m] a l:m l m R = a[m:r] R a[m:r] a m:r m r L.append(1000000009) L.append L append 1000000009 R.append(1000000009) R.append R append 1000000009 i,j = 0,0 i 0 j 0 for k in range(l,r):
        if L[i]<=R[j]:
            a[k] = L[i]
            i += 1
        else :
            a[k] = R[j]
            j += 1
        c+=1 k range(l,r) range l r if L[i]<=R[j]:
            a[k] = L[i]
            i += 1
        else :
            a[k] = R[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 += 1 i 1 a[k] = R[j] a[k] a k R[j] R j j += 1 j 1 c+=1 c 1 a a l l m m r r def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r) mergeSort if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r) l+1<r l+1 l 1 r m = (l+r)//2 m (l+r)//2 l+r l r 2 mergeSort(a,l,m) mergeSort a l m mergeSort(a,m,r) mergeSort a m r merge(a,l,m,r) merge a l m r a a l l r r def main():
    n = int(input())
    a = list(map(int,input().split()))
    mergeSort(a,0,n)
    print (' '.join(map(str,a)))
    print (c) main 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 mergeSort(a,0,n) mergeSort a 0 n print (' '.join(map(str,a))) print ' '.join(map(str,a)) ' '.join ' ' join map(str,a) map str a print (c) print c if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main c = 0 0 c def merge(a,l,m,r):
    global c
    n1 = m-l
    n2 = r-m
    L = a[l:m]
    R = a[m:r]
    L.append(1000000009)
    R.append(1000000009)
    i,j = 0,0
    for k in range(l,r):
        if L[i]<=R[j]:
            a[k] = L[i]
            i += 1
        else :
            a[k] = R[j]
            j += 1
        c+=1 def merge(a,l,m,r):
    global c
    n1 = m-l
    n2 = r-m
    L = a[l:m]
    R = a[m:r]
    L.append(1000000009)
    R.append(1000000009)
    i,j = 0,0
    for k in range(l,r):
        if L[i]<=R[j]:
            a[k] = L[i]
            i += 1
        else :
            a[k] = R[j]
            j += 1
        c+=1 merge def main():
    n = int(input())
    a = list(map(int,input().split()))
    mergeSort(a,0,n)
    print (' '.join(map(str,a)))
    print (c) def main():
    n = int(input())
    a = list(map(int,input().split()))
    mergeSort(a,0,n)
    print (' '.join(map(str,a)))
    print (c) main def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r) def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r) mergeSort
c = 0

def merge(a,l,m,r):
    global c
    n1 = m-l
    n2 = r-m
    L = a[l:m]
    R = a[m:r]
    L.append(1000000009)
    R.append(1000000009)
    i,j = 0,0
    for k in range(l,r):
        if L[i]<=R[j]:
            a[k] = L[i]
            i += 1
        else :
            a[k] = R[j]
            j += 1
        c+=1

def mergeSort(a,l,r):
    if l+1<r:
        m = (l+r)//2
        mergeSort(a,l,m)
        mergeSort(a,m,r)
        merge(a,l,m,r)

def main():
    n = int(input())
    a = list(map(int,input().split()))
    mergeSort(a,0,n)
    print (' '.join(map(str,a)))
    print (c)

if __name__ == '__main__':
    main()


