n=int(input())
A=tuple(map(int, input().split()))
cnt=0

def merge_sort(A,cnt):
    m=len(A)
    if m == 1:
        return A,cnt
    else:
        mid=(m+1)//2
        A1=tuple(A[:mid])
        A2=tuple(A[mid:])
        A1,cnt=merge_sort(A1,cnt)
        A2,cnt=merge_sort(A2,cnt)
        n1=len(A1)
        n2=len(A2)
        i1=0
        i2=0
        ans=[0]*(n1+n2)
        j=0
        while j < n1+n2:
            if i1 == n1:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            elif i2 == n2:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            elif A1[i1] < A2[i2]:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            else:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            j += 1
        return ans,cnt

sorted_A,cnt=merge_sort(A,0)
print(*sorted_A)
print(cnt)

            

         n=int(input()) n int(input()) int input() input A=tuple(map(int, input().split())) A tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split cnt=0 cnt 0 def merge_sort(A,cnt):
    m=len(A)
    if m == 1:
        return A,cnt
    else:
        mid=(m+1)//2
        A1=tuple(A[:mid])
        A2=tuple(A[mid:])
        A1,cnt=merge_sort(A1,cnt)
        A2,cnt=merge_sort(A2,cnt)
        n1=len(A1)
        n2=len(A2)
        i1=0
        i2=0
        ans=[0]*(n1+n2)
        j=0
        while j < n1+n2:
            if i1 == n1:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            elif i2 == n2:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            elif A1[i1] < A2[i2]:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            else:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            j += 1
        return ans,cnt merge_sort m=len(A) m len(A) len A if m == 1:
        return A,cnt
    else:
        mid=(m+1)//2
        A1=tuple(A[:mid])
        A2=tuple(A[mid:])
        A1,cnt=merge_sort(A1,cnt)
        A2,cnt=merge_sort(A2,cnt)
        n1=len(A1)
        n2=len(A2)
        i1=0
        i2=0
        ans=[0]*(n1+n2)
        j=0
        while j < n1+n2:
            if i1 == n1:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            elif i2 == n2:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            elif A1[i1] < A2[i2]:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            else:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            j += 1
        return ans,cnt m == 1 m 1 return A,cnt return A,cnt A cnt mid=(m+1)//2 mid (m+1)//2 m+1 m 1 2 A1=tuple(A[:mid]) A1 tuple(A[:mid]) tuple A[:mid] A :mid mid A2=tuple(A[mid:]) A2 tuple(A[mid:]) tuple A[mid:] A mid: mid A1,cnt=merge_sort(A1,cnt) A1 merge_sort(A1,cnt) merge_sort A1 cnt cnt A2,cnt=merge_sort(A2,cnt) A2 merge_sort(A2,cnt) merge_sort A2 cnt cnt n1=len(A1) n1 len(A1) len A1 n2=len(A2) n2 len(A2) len A2 i1=0 i1 0 i2=0 i2 0 ans=[0]*(n1+n2) ans [0]*(n1+n2) [0] 0 n1+n2 n1 n2 j=0 j 0 while j < n1+n2:
            if i1 == n1:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            elif i2 == n2:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            elif A1[i1] < A2[i2]:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            else:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            j += 1
         j < n1+n2 j n1+n2 n1 n2 if i1 == n1:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            elif i2 == n2:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            elif A1[i1] < A2[i2]:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            else:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
             i1 == n1 i1 n1 ans[j]=A2[i2] ans[j] ans j A2[i2] A2 i2 i2+=1 i2 1 cnt+=1 cnt 1 elif i2 == n2:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
             i2 == n2 i2 n2 ans[j]=A1[i1] ans[j] ans j A1[i1] A1 i1 i1+=1 i1 1 cnt+=1 cnt 1 elif A1[i1] < A2[i2]:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
             A1[i1] < A2[i2] A1[i1] A1 i1 A2[i2] A2 i2 ans[j]=A1[i1] ans[j] ans j A1[i1] A1 i1 i1+=1 i1 1 cnt+=1 cnt 1 ans[j]=A2[i2] ans[j] ans j A2[i2] A2 i2 i2+=1 i2 1 cnt+=1 cnt 1 j += 1 j 1 return ans,cnt return ans,cnt ans cnt A A cnt cnt sorted_A,cnt=merge_sort(A,0) sorted_A merge_sort(A,0) merge_sort A 0 cnt print(*sorted_A) print *sorted_A sorted_A print(cnt) print cnt A=tuple(map(int, input().split())) tuple(map(int, input().split())) A cnt=merge_sort(A,0) merge_sort(A,0) cnt sorted_A,cnt=merge_sort(A,0) merge_sort(A,0) sorted_A n=int(input()) int(input()) n cnt=0 0 cnt def merge_sort(A,cnt):
    m=len(A)
    if m == 1:
        return A,cnt
    else:
        mid=(m+1)//2
        A1=tuple(A[:mid])
        A2=tuple(A[mid:])
        A1,cnt=merge_sort(A1,cnt)
        A2,cnt=merge_sort(A2,cnt)
        n1=len(A1)
        n2=len(A2)
        i1=0
        i2=0
        ans=[0]*(n1+n2)
        j=0
        while j < n1+n2:
            if i1 == n1:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            elif i2 == n2:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            elif A1[i1] < A2[i2]:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            else:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            j += 1
        return ans,cnt def merge_sort(A,cnt):
    m=len(A)
    if m == 1:
        return A,cnt
    else:
        mid=(m+1)//2
        A1=tuple(A[:mid])
        A2=tuple(A[mid:])
        A1,cnt=merge_sort(A1,cnt)
        A2,cnt=merge_sort(A2,cnt)
        n1=len(A1)
        n2=len(A2)
        i1=0
        i2=0
        ans=[0]*(n1+n2)
        j=0
        while j < n1+n2:
            if i1 == n1:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            elif i2 == n2:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            elif A1[i1] < A2[i2]:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            else:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            j += 1
        return ans,cnt merge_sort
n=int(input())
A=tuple(map(int, input().split()))
cnt=0

def merge_sort(A,cnt):
    m=len(A)
    if m == 1:
        return A,cnt
    else:
        mid=(m+1)//2
        A1=tuple(A[:mid])
        A2=tuple(A[mid:])
        A1,cnt=merge_sort(A1,cnt)
        A2,cnt=merge_sort(A2,cnt)
        n1=len(A1)
        n2=len(A2)
        i1=0
        i2=0
        ans=[0]*(n1+n2)
        j=0
        while j < n1+n2:
            if i1 == n1:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            elif i2 == n2:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            elif A1[i1] < A2[i2]:
                ans[j]=A1[i1]
                i1+=1
                cnt+=1
            else:
                ans[j]=A2[i2]
                i2+=1
                cnt+=1
            j += 1
        return ans,cnt

sorted_A,cnt=merge_sort(A,0)
print(*sorted_A)
print(cnt)

            

        
