INFTY=1000000000

n=int(input())
A=list(map(int,input().split()))

def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid
    L=[A[left+i] for i in range(n1)]
    R=[A[mid+i] for i in range(n2)]
    L.append(INFTY)
    R.append(INFTY)
    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
    return cnt

def mergeSort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cnt1=mergeSort(A,left,mid)
        cnt2=mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cnt1+cnt2
    return 0

cnt=mergeSort(A,0,n)
print(' '.join(map(str,A)))
print(cnt) INFTY=1000000000 INFTY 1000000000 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 def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid
    L=[A[left+i] for i in range(n1)]
    R=[A[mid+i] for i in range(n2)]
    L.append(INFTY)
    R.append(INFTY)
    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
    return cnt merge cnt=0 cnt 0 n1=mid-left n1 mid-left mid left n2=right-mid n2 right-mid right mid 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)] L [A[left+i] for i in range(n1)] A[mid+i] for i in range(n2) for i in range(n2) i range(n2) range n2 for i in range(n2) A[mid+i] A mid+i mid i R=[A[mid+i] for i in range(n2)] R [A[mid+i] for i in range(n2)] L.append(INFTY) L.append L append INFTY R.append(INFTY) R.append R append INFTY i=0 i 0 j=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 mid mid right right def mergeSort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cnt1=mergeSort(A,left,mid)
        cnt2=mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cnt1+cnt2
    return 0 mergeSort if left+1<right:
        mid=(left+right)//2
        cnt1=mergeSort(A,left,mid)
        cnt2=mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cnt1+cnt2
     left+1<right left+1 left 1 right mid=(left+right)//2 mid (left+right)//2 left+right left right 2 cnt1=mergeSort(A,left,mid) cnt1 mergeSort(A,left,mid) mergeSort A left mid cnt2=mergeSort(A,mid,right) cnt2 mergeSort(A,mid,right) mergeSort A mid right return merge(A,left,mid,right)+cnt1+cnt2 merge(A,left,mid,right)+cnt1+cnt2 merge(A,left,mid,right)+cnt1 merge(A,left,mid,right) merge A left mid right cnt1 cnt2 return 0 0 A A left left right right cnt=mergeSort(A,0,n) cnt 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(cnt) print cnt cnt=mergeSort(A,0,n) mergeSort(A,0,n) cnt INFTY=1000000000 1000000000 INFTY A=list(map(int,input().split())) list(map(int,input().split())) A def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid
    L=[A[left+i] for i in range(n1)]
    R=[A[mid+i] for i in range(n2)]
    L.append(INFTY)
    R.append(INFTY)
    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
    return cnt def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid
    L=[A[left+i] for i in range(n1)]
    R=[A[mid+i] for i in range(n2)]
    L.append(INFTY)
    R.append(INFTY)
    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
    return cnt merge def mergeSort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cnt1=mergeSort(A,left,mid)
        cnt2=mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cnt1+cnt2
    return 0 def mergeSort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cnt1=mergeSort(A,left,mid)
        cnt2=mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cnt1+cnt2
    return 0 mergeSort n=int(input()) int(input()) n
INFTY=1000000000

n=int(input())
A=list(map(int,input().split()))

def merge(A,left,mid,right):
    cnt=0
    n1=mid-left
    n2=right-mid
    L=[A[left+i] for i in range(n1)]
    R=[A[mid+i] for i in range(n2)]
    L.append(INFTY)
    R.append(INFTY)
    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
    return cnt

def mergeSort(A,left,right):
    if left+1<right:
        mid=(left+right)//2
        cnt1=mergeSort(A,left,mid)
        cnt2=mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cnt1+cnt2
    return 0

cnt=mergeSort(A,0,n)
print(' '.join(map(str,A)))
print(cnt)
