num = 0
def marge_sort(array):
    global num
    if len(array) < 2: return array
    
    mid = len(array) // 2
    left = marge_sort(array[:mid])
    right = marge_sort(array[mid:])
    
    len_l, len_r = len(left), len(right)
    left += [float("inf")]
    right += [float("inf")]
    
    marray = [0] * (len_l + len_r)
    
    l, r = 0, 0
    for i in range(len_l + len_r):
        num += 1
        if left[l] <= right[r]:
            marray[i] = left[l]
            l += 1
        else:
            marray[i] = right[r]
            r += 1
        
    return marray

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

print(" ".join(map(str, marge_sort(a))))
print(num) num = 0 num 0 def marge_sort(array):
    global num
    if len(array) < 2: return array
    
    mid = len(array) // 2
    left = marge_sort(array[:mid])
    right = marge_sort(array[mid:])
    
    len_l, len_r = len(left), len(right)
    left += [float("inf")]
    right += [float("inf")]
    
    marray = [0] * (len_l + len_r)
    
    l, r = 0, 0
    for i in range(len_l + len_r):
        num += 1
        if left[l] <= right[r]:
            marray[i] = left[l]
            l += 1
        else:
            marray[i] = right[r]
            r += 1
        
    return marray marge_sort global num if len(array) < 2: return array
    
     len(array) < 2 len(array) len array 2 mid = len(array) // 2 mid len(array) // 2 len(array) len array 2 left = marge_sort(array[:mid]) left marge_sort(array[:mid]) marge_sort array[:mid] array :mid mid right = marge_sort(array[mid:]) right marge_sort(array[mid:]) marge_sort array[mid:] array mid: mid len_l, len_r = len(left), len(right) len_l len(left) len left len_r len(right) len right left += [float("inf")] left [float("inf")] float("inf") float "inf" right += [float("inf")] right [float("inf")] float("inf") float "inf" marray = [0] * (len_l + len_r) marray [0] * (len_l + len_r) [0] 0 len_l + len_r len_l len_r l, r = 0, 0 l 0 r 0 for i in range(len_l + len_r):
        num += 1
        if left[l] <= right[r]:
            marray[i] = left[l]
            l += 1
        else:
            marray[i] = right[r]
            r += 1
        
     i range(len_l + len_r) range len_l + len_r len_l len_r num += 1 num 1 if left[l] <= right[r]:
            marray[i] = left[l]
            l += 1
        else:
            marray[i] = right[r]
            r += 1
        
     left[l] <= right[r] left[l] left l right[r] right r marray[i] = left[l] marray[i] marray i left[l] left l l += 1 l 1 marray[i] = right[r] marray[i] marray i right[r] right r r += 1 r 1 return marray marray array array 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 print(" ".join(map(str, marge_sort(a)))) print " ".join(map(str, marge_sort(a))) " ".join " " join map(str, marge_sort(a)) map str marge_sort(a) marge_sort a print(num) print num def marge_sort(array):
    global num
    if len(array) < 2: return array
    
    mid = len(array) // 2
    left = marge_sort(array[:mid])
    right = marge_sort(array[mid:])
    
    len_l, len_r = len(left), len(right)
    left += [float("inf")]
    right += [float("inf")]
    
    marray = [0] * (len_l + len_r)
    
    l, r = 0, 0
    for i in range(len_l + len_r):
        num += 1
        if left[l] <= right[r]:
            marray[i] = left[l]
            l += 1
        else:
            marray[i] = right[r]
            r += 1
        
    return marray def marge_sort(array):
    global num
    if len(array) < 2: return array
    
    mid = len(array) // 2
    left = marge_sort(array[:mid])
    right = marge_sort(array[mid:])
    
    len_l, len_r = len(left), len(right)
    left += [float("inf")]
    right += [float("inf")]
    
    marray = [0] * (len_l + len_r)
    
    l, r = 0, 0
    for i in range(len_l + len_r):
        num += 1
        if left[l] <= right[r]:
            marray[i] = left[l]
            l += 1
        else:
            marray[i] = right[r]
            r += 1
        
    return marray marge_sort a = list(map(int, input().split())) list(map(int, input().split())) a num = 0 0 num n = int(input()) int(input()) n
num = 0
def marge_sort(array):
    global num
    if len(array) < 2: return array
    
    mid = len(array) // 2
    left = marge_sort(array[:mid])
    right = marge_sort(array[mid:])
    
    len_l, len_r = len(left), len(right)
    left += [float("inf")]
    right += [float("inf")]
    
    marray = [0] * (len_l + len_r)
    
    l, r = 0, 0
    for i in range(len_l + len_r):
        num += 1
        if left[l] <= right[r]:
            marray[i] = left[l]
            l += 1
        else:
            marray[i] = right[r]
            r += 1
        
    return marray

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

print(" ".join(map(str, marge_sort(a))))
print(num)
