n=int(input())
nums=list(map(int,input().split()))
count=0
def merge(nums,left,mid,right):
    global count
    inf=10**9
    L=nums[left:mid]+[inf]
    R=nums[mid:right]+[inf]
    i=0
    j=0
    for k in range(left,right):
        count+=1
        if R[j]>=L[i]:
            nums[k]=L[i]
            i+=1

        else:
            nums[k]=R[j]
            j+=1

def merge_sort(nums,left,right):
    if left+1<right:
        mid=(right+left)//2
        merge_sort(nums,left,mid)
        merge_sort(nums,mid,right)
        merge(nums,left,mid,right)

merge_sort(nums,0,n)

def show(nums):
    l=len(nums)
    for i in range(l):
        if i!=l-1:
            print(nums[i],end=" ")
            
        else:
            print(nums[i])
            
show(nums)
print(count) n=int(input()) n int(input()) int input() input nums=list(map(int,input().split())) nums list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split count=0 count 0 def merge(nums,left,mid,right):
    global count
    inf=10**9
    L=nums[left:mid]+[inf]
    R=nums[mid:right]+[inf]
    i=0
    j=0
    for k in range(left,right):
        count+=1
        if R[j]>=L[i]:
            nums[k]=L[i]
            i+=1

        else:
            nums[k]=R[j]
            j+=1 merge global count inf=10**9 inf 10**9 10 9 L=nums[left:mid]+[inf] L nums[left:mid]+[inf] nums[left:mid] nums left:mid left mid [inf] inf R=nums[mid:right]+[inf] R nums[mid:right]+[inf] nums[mid:right] nums mid:right mid right [inf] inf i=0 i 0 j=0 j 0 for k in range(left,right):
        count+=1
        if R[j]>=L[i]:
            nums[k]=L[i]
            i+=1

        else:
            nums[k]=R[j]
            j+=1 k range(left,right) range left right count+=1 count 1 if R[j]>=L[i]:
            nums[k]=L[i]
            i+=1

        else:
            nums[k]=R[j]
            j+=1 R[j]>=L[i] R[j] R j L[i] L i nums[k]=L[i] nums[k] nums k L[i] L i i+=1 i 1 nums[k]=R[j] nums[k] nums k R[j] R j j+=1 j 1 nums nums left left mid mid right right def merge_sort(nums,left,right):
    if left+1<right:
        mid=(right+left)//2
        merge_sort(nums,left,mid)
        merge_sort(nums,mid,right)
        merge(nums,left,mid,right) merge_sort if left+1<right:
        mid=(right+left)//2
        merge_sort(nums,left,mid)
        merge_sort(nums,mid,right)
        merge(nums,left,mid,right) left+1<right left+1 left 1 right mid=(right+left)//2 mid (right+left)//2 right+left right left 2 merge_sort(nums,left,mid) merge_sort nums left mid merge_sort(nums,mid,right) merge_sort nums mid right merge(nums,left,mid,right) merge nums left mid right nums nums left left right right merge_sort(nums,0,n) merge_sort nums 0 n def show(nums):
    l=len(nums)
    for i in range(l):
        if i!=l-1:
            print(nums[i],end=" ")
            
        else:
            print(nums[i])
             show l=len(nums) l len(nums) len nums for i in range(l):
        if i!=l-1:
            print(nums[i],end=" ")
            
        else:
            print(nums[i])
             i range(l) range l if i!=l-1:
            print(nums[i],end=" ")
            
        else:
            print(nums[i])
             i!=l-1 i l-1 l 1 print(nums[i],end=" ") print nums[i] nums i end=" " end " " print(nums[i]) print nums[i] nums i nums nums show(nums) show nums print(count) print count def show(nums):
    l=len(nums)
    for i in range(l):
        if i!=l-1:
            print(nums[i],end=" ")
            
        else:
            print(nums[i])
             def show(nums):
    l=len(nums)
    for i in range(l):
        if i!=l-1:
            print(nums[i],end=" ")
            
        else:
            print(nums[i])
             show count=0 0 count def merge_sort(nums,left,right):
    if left+1<right:
        mid=(right+left)//2
        merge_sort(nums,left,mid)
        merge_sort(nums,mid,right)
        merge(nums,left,mid,right) def merge_sort(nums,left,right):
    if left+1<right:
        mid=(right+left)//2
        merge_sort(nums,left,mid)
        merge_sort(nums,mid,right)
        merge(nums,left,mid,right) merge_sort nums=list(map(int,input().split())) list(map(int,input().split())) nums n=int(input()) int(input()) n def merge(nums,left,mid,right):
    global count
    inf=10**9
    L=nums[left:mid]+[inf]
    R=nums[mid:right]+[inf]
    i=0
    j=0
    for k in range(left,right):
        count+=1
        if R[j]>=L[i]:
            nums[k]=L[i]
            i+=1

        else:
            nums[k]=R[j]
            j+=1 def merge(nums,left,mid,right):
    global count
    inf=10**9
    L=nums[left:mid]+[inf]
    R=nums[mid:right]+[inf]
    i=0
    j=0
    for k in range(left,right):
        count+=1
        if R[j]>=L[i]:
            nums[k]=L[i]
            i+=1

        else:
            nums[k]=R[j]
            j+=1 merge
n=int(input())
nums=list(map(int,input().split()))
count=0
def merge(nums,left,mid,right):
    global count
    inf=10**9
    L=nums[left:mid]+[inf]
    R=nums[mid:right]+[inf]
    i=0
    j=0
    for k in range(left,right):
        count+=1
        if R[j]>=L[i]:
            nums[k]=L[i]
            i+=1

        else:
            nums[k]=R[j]
            j+=1

def merge_sort(nums,left,right):
    if left+1<right:
        mid=(right+left)//2
        merge_sort(nums,left,mid)
        merge_sort(nums,mid,right)
        merge(nums,left,mid,right)

merge_sort(nums,0,n)

def show(nums):
    l=len(nums)
    for i in range(l):
        if i!=l-1:
            print(nums[i],end=" ")
            
        else:
            print(nums[i])
            
show(nums)
print(count)
