inf=10**10
def merge(a,left,cen,right):
    cnt=0
    n1=cen-left
    n2=right-cen
    L=[a[left+i] for i in range(n1)]+[inf]
    R=[a[cen+i] for i in range(n2)]+[inf]
    i,j=0,0
    for k in range(left,right):
        cnt+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return cnt

def sorting(a,left,right):
    if left+1<right:
        m=(left+right)//2
        cntlr=sorting(a,left,m)+sorting(a,m,right)
        return merge(a,left,m,right)+cntlr
    return 0

n=int(input())
a=list(map(int,input().split()))
ans=sorting(a,0,n)
print(*a)
print(ans) inf=10**10 inf 10**10 10 10 def merge(a,left,cen,right):
    cnt=0
    n1=cen-left
    n2=right-cen
    L=[a[left+i] for i in range(n1)]+[inf]
    R=[a[cen+i] for i in range(n2)]+[inf]
    i,j=0,0
    for k in range(left,right):
        cnt+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return cnt merge cnt=0 cnt 0 n1=cen-left n1 cen-left cen left n2=right-cen n2 right-cen right cen a[left+i] for i in range(n1) for i in range(n1) i range(n1) range n1 for i in range(n1) a[left+i] a left+i left i L=[a[left+i] for i in range(n1)]+[inf] L [a[left+i] for i in range(n1)]+[inf] [a[left+i] for i in range(n1)] [inf] inf a[cen+i] for i in range(n2) for i in range(n2) i range(n2) range n2 for i in range(n2) a[cen+i] a cen+i cen i R=[a[cen+i] for i in range(n2)]+[inf] R [a[cen+i] for i in range(n2)]+[inf] [a[cen+i] for i in range(n2)] [inf] inf i,j=0,0 i 0 j 0 for k in range(left,right):
        cnt+=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 cnt+=1 cnt 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 cnt cnt a a left left cen cen right right def sorting(a,left,right):
    if left+1<right:
        m=(left+right)//2
        cntlr=sorting(a,left,m)+sorting(a,m,right)
        return merge(a,left,m,right)+cntlr
    return 0 sorting if left+1<right:
        m=(left+right)//2
        cntlr=sorting(a,left,m)+sorting(a,m,right)
        return merge(a,left,m,right)+cntlr
     left+1<right left+1 left 1 right m=(left+right)//2 m (left+right)//2 left+right left right 2 cntlr=sorting(a,left,m)+sorting(a,m,right) cntlr sorting(a,left,m)+sorting(a,m,right) sorting(a,left,m) sorting a left m sorting(a,m,right) sorting a m right return merge(a,left,m,right)+cntlr merge(a,left,m,right)+cntlr merge(a,left,m,right) merge a left m right cntlr 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=sorting(a,0,n) ans sorting(a,0,n) sorting a 0 n print(*a) print *a a print(ans) print ans inf=10**10 10**10 inf def sorting(a,left,right):
    if left+1<right:
        m=(left+right)//2
        cntlr=sorting(a,left,m)+sorting(a,m,right)
        return merge(a,left,m,right)+cntlr
    return 0 def sorting(a,left,right):
    if left+1<right:
        m=(left+right)//2
        cntlr=sorting(a,left,m)+sorting(a,m,right)
        return merge(a,left,m,right)+cntlr
    return 0 sorting n=int(input()) int(input()) n def merge(a,left,cen,right):
    cnt=0
    n1=cen-left
    n2=right-cen
    L=[a[left+i] for i in range(n1)]+[inf]
    R=[a[cen+i] for i in range(n2)]+[inf]
    i,j=0,0
    for k in range(left,right):
        cnt+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return cnt def merge(a,left,cen,right):
    cnt=0
    n1=cen-left
    n2=right-cen
    L=[a[left+i] for i in range(n1)]+[inf]
    R=[a[cen+i] for i in range(n2)]+[inf]
    i,j=0,0
    for k in range(left,right):
        cnt+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return cnt merge a=list(map(int,input().split())) list(map(int,input().split())) a ans=sorting(a,0,n) sorting(a,0,n) ans
inf=10**10
def merge(a,left,cen,right):
    cnt=0
    n1=cen-left
    n2=right-cen
    L=[a[left+i] for i in range(n1)]+[inf]
    R=[a[cen+i] for i in range(n2)]+[inf]
    i,j=0,0
    for k in range(left,right):
        cnt+=1
        if L[i]<=R[j]:
            a[k]=L[i]
            i+=1
        else:
            a[k]=R[j]
            j+=1
    return cnt

def sorting(a,left,right):
    if left+1<right:
        m=(left+right)//2
        cntlr=sorting(a,left,m)+sorting(a,m,right)
        return merge(a,left,m,right)+cntlr
    return 0

n=int(input())
a=list(map(int,input().split()))
ans=sorting(a,0,n)
print(*a)
print(ans)
