def merge(A,l,m,r):
    L=A[l:m];R=A[m:r]
    L.append(INF);R.append(INF)
    global cnt

    i=j=0    
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1
        else:
            A[k]=R[j]
            j+=1        

def mergeSort(A,l,r):
    if l+1==r:
        pass
    else:
        m=(l+r)//2
        mergeSort(A,l,m)
        mergeSort(A,m,r)
        merge(A,l,m,r)

INF=10**9+1
n=int(input())
S=list(map(int,input().split()))
cnt=0

mergeSort(S,0,n)

for i in range(n):
    if i<n-1:
        print(S[i],end=' ')
    else:
        print(S[i])
print(cnt) def merge(A,l,m,r):
    L=A[l:m];R=A[m:r]
    L.append(INF);R.append(INF)
    global cnt

    i=j=0    
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1
        else:
            A[k]=R[j]
            j+=1         merge L=A[l:m] L A[l:m] A l:m l m R=A[m:r] R A[m:r] A m:r m r L.append(INF) L.append L append INF R.append(INF) R.append R append INF global cnt i=j=0 i 0 =j=0 j 0 for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1
        else:
            A[k]=R[j]
            j+=1         k range(l,r) range l r 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 A A l l m m r r def mergeSort(A,l,r):
    if l+1==r:
        pass
    else:
        m=(l+r)//2
        mergeSort(A,l,m)
        mergeSort(A,m,r)
        merge(A,l,m,r) mergeSort if l+1==r:
        pass
    else:
        m=(l+r)//2
        mergeSort(A,l,m)
        mergeSort(A,m,r)
        merge(A,l,m,r) l+1==r l+1 l 1 r m=(l+r)//2 m (l+r)//2 l+r l r 2 mergeSort(A,l,m) mergeSort A l m mergeSort(A,m,r) mergeSort A m r merge(A,l,m,r) merge A l m r A A l l r r INF=10**9+1 INF 10**9+1 10**9 10 9 1 n=int(input()) n int(input()) int input() input S=list(map(int,input().split())) S list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split cnt=0 cnt 0 mergeSort(S,0,n) mergeSort S 0 n for i in range(n):
    if i<n-1:
        print(S[i],end=' ')
    else:
        print(S[i]) i range(n) range n if i<n-1:
        print(S[i],end=' ')
    else:
        print(S[i]) i<n-1 i n-1 n 1 print(S[i],end=' ') print S[i] S i end=' ' end ' ' print(S[i]) print S[i] S i print(cnt) print cnt S=list(map(int,input().split())) list(map(int,input().split())) S def merge(A,l,m,r):
    L=A[l:m];R=A[m:r]
    L.append(INF);R.append(INF)
    global cnt

    i=j=0    
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1
        else:
            A[k]=R[j]
            j+=1         def merge(A,l,m,r):
    L=A[l:m];R=A[m:r]
    L.append(INF);R.append(INF)
    global cnt

    i=j=0    
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1
        else:
            A[k]=R[j]
            j+=1         merge INF=10**9+1 10**9+1 INF cnt=0 0 cnt def mergeSort(A,l,r):
    if l+1==r:
        pass
    else:
        m=(l+r)//2
        mergeSort(A,l,m)
        mergeSort(A,m,r)
        merge(A,l,m,r) def mergeSort(A,l,r):
    if l+1==r:
        pass
    else:
        m=(l+r)//2
        mergeSort(A,l,m)
        mergeSort(A,m,r)
        merge(A,l,m,r) mergeSort n=int(input()) int(input()) n
def merge(A,l,m,r):
    L=A[l:m];R=A[m:r]
    L.append(INF);R.append(INF)
    global cnt

    i=j=0    
    for k in range(l,r):
        cnt+=1
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1
        else:
            A[k]=R[j]
            j+=1        

def mergeSort(A,l,r):
    if l+1==r:
        pass
    else:
        m=(l+r)//2
        mergeSort(A,l,m)
        mergeSort(A,m,r)
        merge(A,l,m,r)

INF=10**9+1
n=int(input())
S=list(map(int,input().split()))
cnt=0

mergeSort(S,0,n)

for i in range(n):
    if i<n-1:
        print(S[i],end=' ')
    else:
        print(S[i])
print(cnt)
