def merge(a, left, mid, right):
    L = a[left:mid] + [INF]
    R = a[mid:right] + [INF]
    
    i = 0
    j = 0
    for k in range(left, right):
     
        global idx
        idx += 1
        if( L[i] <= R[j] ):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1

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


INF = 1000000000
idx = 0
n = int(input())
a = [int(i) for i in input().split()]
merge_sort(a,0,len(a))
print(*a)
print(idx) def merge(a, left, mid, right):
    L = a[left:mid] + [INF]
    R = a[mid:right] + [INF]
    
    i = 0
    j = 0
    for k in range(left, right):
     
        global idx
        idx += 1
        if( L[i] <= R[j] ):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1 merge L = a[left:mid] + [INF] L a[left:mid] + [INF] a[left:mid] a left:mid left mid [INF] INF R = a[mid:right] + [INF] R a[mid:right] + [INF] a[mid:right] a mid:right mid right [INF] INF i = 0 i 0 j = 0 j 0 for k in range(left, right):
     
        global idx
        idx += 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 global idx idx += 1 idx 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 left left mid mid right right def merge_sort(a, left, right):
    if( left + 1 < right ):
        mid = (left + right) // 2 
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) merge_sort if( left + 1 < right ):
        mid = (left + right) // 2 
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 merge_sort(a, left, mid) merge_sort a left mid merge_sort(a, mid, right) merge_sort a mid right merge(a, left, mid, right) merge a left mid right a a left left right right INF = 1000000000 INF 1000000000 idx = 0 idx 0 n = int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a = [int(i) for i in input().split()] a [int(i) for i in input().split()] merge_sort(a,0,len(a)) merge_sort a 0 len(a) len a print(*a) print *a a print(idx) print idx n = int(input()) int(input()) n INF = 1000000000 1000000000 INF idx = 0 0 idx a = [int(i) for i in input().split()] [int(i) for i in input().split()] a def merge(a, left, mid, right):
    L = a[left:mid] + [INF]
    R = a[mid:right] + [INF]
    
    i = 0
    j = 0
    for k in range(left, right):
     
        global idx
        idx += 1
        if( L[i] <= R[j] ):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1 def merge(a, left, mid, right):
    L = a[left:mid] + [INF]
    R = a[mid:right] + [INF]
    
    i = 0
    j = 0
    for k in range(left, right):
     
        global idx
        idx += 1
        if( L[i] <= R[j] ):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1 merge def merge_sort(a, left, right):
    if( left + 1 < right ):
        mid = (left + right) // 2 
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) def merge_sort(a, left, right):
    if( left + 1 < right ):
        mid = (left + right) // 2 
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right) merge_sort
def merge(a, left, mid, right):
    L = a[left:mid] + [INF]
    R = a[mid:right] + [INF]
    
    i = 0
    j = 0
    for k in range(left, right):
     
        global idx
        idx += 1
        if( L[i] <= R[j] ):
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1

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


INF = 1000000000
idx = 0
n = int(input())
a = [int(i) for i in input().split()]
merge_sort(a,0,len(a))
print(*a)
print(idx)
