from array import array

def readinput():
    n=int(input())
    a=array('L',list(map(int,input().split())))
    return n,a

count=0
def merge(a,left,mid,right):
    INFTY=10**9+1
    global count
    n1=mid-left
    n2=right-mid
    #L=[a[left+i] for i in range(n1)]
    L=a[left:mid]
    L.append(INFTY)

    #R=[a[mid+i] for i in range(n2)]
    R=a[mid:right]
    R.append(INFTY)

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

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)
    return

def main(n,a):
    global count
    mergeSort(a,0,n)
    return a,count

if __name__=='__main__':
    n,a=readinput()
    a,count=main(n,a)
    print(' '.join(map(str,a)))
    print(count) from array import array def readinput():
    n=int(input())
    a=array('L',list(map(int,input().split())))
    return n,a readinput n=int(input()) n int(input()) int input() input a=array('L',list(map(int,input().split()))) a array('L',list(map(int,input().split()))) array 'L' list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split return n,a return n,a n a count=0 count 0 def merge(a,left,mid,right):
    INFTY=10**9+1
    global count
    n1=mid-left
    n2=right-mid
    #L=[a[left+i] for i in range(n1)]
    L=a[left:mid]
    L.append(INFTY)

    #R=[a[mid+i] for i in range(n2)]
    R=a[mid:right]
    R.append(INFTY)

    i=0;j=0
    for k in range(left,right):
        if(L[i]<=R[j]):
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
        count+=1
    merge INFTY=10**9+1 INFTY 10**9+1 10**9 10 9 1 global count n1=mid-left n1 mid-left mid left n2=right-mid n2 right-mid right mid L=a[left:mid] L a[left:mid] a left:mid left mid L.append(INFTY) L.append L append INFTY R=a[mid:right] R a[mid:right] a mid:right mid right R.append(INFTY) R.append R append INFTY i=0 i 0 j=0 j 0 for k in range(left,right):
        if(L[i]<=R[j]):
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
        count+=1
    k range(left,right) range left right 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 count+=1 count 1 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)
    return 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 return a a left left right right def main(n,a):
    global count
    mergeSort(a,0,n)
    return a,count main global count mergeSort(a,0,n) mergeSort a 0 n return a,count return a,count a count n n a a if __name__=='__main__':
    n,a=readinput()
    a,count=main(n,a)
    print(' '.join(map(str,a)))
    print(count) __name__=='__main__' __name__ '__main__' n,a=readinput() n readinput() readinput a a,count=main(n,a) a main(n,a) main n a count print(' '.join(map(str,a))) print ' '.join(map(str,a)) ' '.join ' ' join map(str,a) map str a print(count) print count count=main(n,a) main(n,a) count def main(n,a):
    global count
    mergeSort(a,0,n)
    return a,count def main(n,a):
    global count
    mergeSort(a,0,n)
    return a,count main def merge(a,left,mid,right):
    INFTY=10**9+1
    global count
    n1=mid-left
    n2=right-mid
    #L=[a[left+i] for i in range(n1)]
    L=a[left:mid]
    L.append(INFTY)

    #R=[a[mid+i] for i in range(n2)]
    R=a[mid:right]
    R.append(INFTY)

    i=0;j=0
    for k in range(left,right):
        if(L[i]<=R[j]):
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
        count+=1
    def merge(a,left,mid,right):
    INFTY=10**9+1
    global count
    n1=mid-left
    n2=right-mid
    #L=[a[left+i] for i in range(n1)]
    L=a[left:mid]
    L.append(INFTY)

    #R=[a[mid+i] for i in range(n2)]
    R=a[mid:right]
    R.append(INFTY)

    i=0;j=0
    for k in range(left,right):
        if(L[i]<=R[j]):
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
        count+=1
    merge a=readinput() readinput() a n,a=readinput() readinput() n count=0 0 count a,count=main(n,a) main(n,a) a def readinput():
    n=int(input())
    a=array('L',list(map(int,input().split())))
    return n,a def readinput():
    n=int(input())
    a=array('L',list(map(int,input().split())))
    return n,a readinput 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)
    return 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)
    return mergeSort
from array import array

def readinput():
    n=int(input())
    a=array('L',list(map(int,input().split())))
    return n,a

count=0
def merge(a,left,mid,right):
    INFTY=10**9+1
    global count
    n1=mid-left
    n2=right-mid
    #L=[a[left+i] for i in range(n1)]
    L=a[left:mid]
    L.append(INFTY)

    #R=[a[mid+i] for i in range(n2)]
    R=a[mid:right]
    R.append(INFTY)

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

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)
    return

def main(n,a):
    global count
    mergeSort(a,0,n)
    return a,count

if __name__=='__main__':
    n,a=readinput()
    a,count=main(n,a)
    print(' '.join(map(str,a)))
    print(count)
