inf=float("inf")
def merge(a,left,mid,right):
    count=0
    n1=mid-left
    n2=right-mid
    L=[0]*(n1+1)
    R=[0]*(n2+1)
    for i in range(n1):
        L[i]=a[left+i]
    for i in range(n2):
        R[i]=a[mid+i]
    L[n1]=inf
    R[n2]=inf
    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
    return count

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

def mergeSort(a,left,right):
    if left+1<right:
        mid=(left+right)//2
        return mergeSort(a,left,mid)+mergeSort(a,mid,right)+merge(a,left,mid,right)
    return 0
n=int(input())
*a,=map(int,input().split())
ans=mergeSort(a,0,n)
print(*a)
print(ans)

