def merge(a,left,mid,right):
    count=0
    L=a[left:mid]+[float("inf")]
    R=a[mid:right]+[float("inf")]
    i,j=0,0
    for k in range(left,right):
        count+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return count

def mergeSort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        countl=mergeSort(a,left,mid)
        countr=mergeSort(a,mid,right)
        return merge(a,left,mid,right)+countl+countr
    return 0



n=int(input())
a=list(map(int,input().split()))
ans=mergeSort(a,0,n)
print(" ".join(map(str,a)))
print(ans) def merge(a,left,mid,right):
    count=0
    L=a[left:mid]+[float("inf")]
    R=a[mid:right]+[float("inf")]
    i,j=0,0
    for k in range(left,right):
        count+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return count merge count=0 count 0 L=a[left:mid]+[float("inf")] L a[left:mid]+[float("inf")] a[left:mid] a left:mid left mid [float("inf")] float("inf") float "inf" R=a[mid:right]+[float("inf")] R a[mid:right]+[float("inf")] a[mid:right] a mid:right mid right [float("inf")] float("inf") float "inf" i,j=0,0 i 0 j 0 for k in range(left,right):
        count+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
     k range(left,right) range left right count+=1 count 1 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 return count count a a left left mid mid right right def mergeSort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        countl=mergeSort(a,left,mid)
        countr=mergeSort(a,mid,right)
        return merge(a,left,mid,right)+countl+countr
    return 0 mergeSort if left+1<right:
        mid=(left+right)//2
        countl=mergeSort(a,left,mid)
        countr=mergeSort(a,mid,right)
        return merge(a,left,mid,right)+countl+countr
     left+1<right left+1 left 1 right mid=(left+right)//2 mid (left+right)//2 left+right left right 2 countl=mergeSort(a,left,mid) countl mergeSort(a,left,mid) mergeSort a left mid countr=mergeSort(a,mid,right) countr mergeSort(a,mid,right) mergeSort a mid right return merge(a,left,mid,right)+countl+countr merge(a,left,mid,right)+countl+countr merge(a,left,mid,right)+countl merge(a,left,mid,right) merge a left mid right countl countr return 0 0 a a left left right right 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 ans=mergeSort(a,0,n) ans 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(ans) print ans def merge(a,left,mid,right):
    count=0
    L=a[left:mid]+[float("inf")]
    R=a[mid:right]+[float("inf")]
    i,j=0,0
    for k in range(left,right):
        count+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return count def merge(a,left,mid,right):
    count=0
    L=a[left:mid]+[float("inf")]
    R=a[mid:right]+[float("inf")]
    i,j=0,0
    for k in range(left,right):
        count+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return count merge def mergeSort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        countl=mergeSort(a,left,mid)
        countr=mergeSort(a,mid,right)
        return merge(a,left,mid,right)+countl+countr
    return 0 def mergeSort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        countl=mergeSort(a,left,mid)
        countr=mergeSort(a,mid,right)
        return merge(a,left,mid,right)+countl+countr
    return 0 mergeSort n=int(input()) int(input()) n a=list(map(int,input().split())) list(map(int,input().split())) a ans=mergeSort(a,0,n) mergeSort(a,0,n) ans
def merge(a,left,mid,right):
    count=0
    L=a[left:mid]+[float("inf")]
    R=a[mid:right]+[float("inf")]
    i,j=0,0
    for k in range(left,right):
        count+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return count

def mergeSort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        countl=mergeSort(a,left,mid)
        countr=mergeSort(a,mid,right)
        return merge(a,left,mid,right)+countl+countr
    return 0



n=int(input())
a=list(map(int,input().split()))
ans=mergeSort(a,0,n)
print(" ".join(map(str,a)))
print(ans)
