cnt = 0
def merge_sort(array):
    global cnt
    if len(array) <= 1:
        return array
    mid = len(array) // 2
    left = array[:mid]
    right = array[mid:]
    cnt += len(left) + len(right)
    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right)

def merge(left, right):
    list = []
    l_index, r_index = 0, 0
    while l_index < len(left) and r_index < len(right):
        if left[l_index] <= right[r_index]:
            list.append(left[l_index])
            l_index += 1
        else:
            list.append(right[r_index])
            r_index += 1
    if l_index < len(left):
        list.extend(left[l_index:])
    if r_index < len(right):
        list.extend(right[r_index:])
    
    return list

n = int(input())
S = list(map(int, input().split()))
array = merge_sort(S)
print(" ".join(map(str, array)))
print(cnt) cnt = 0 cnt 0 def merge_sort(array):
    global cnt
    if len(array) <= 1:
        return array
    mid = len(array) // 2
    left = array[:mid]
    right = array[mid:]
    cnt += len(left) + len(right)
    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right) merge_sort global cnt if len(array) <= 1:
        return array
     len(array) <= 1 len(array) len array 1 return array array mid = len(array) // 2 mid len(array) // 2 len(array) len array 2 left = array[:mid] left array[:mid] array :mid mid right = array[mid:] right array[mid:] array mid: mid cnt += len(left) + len(right) cnt len(left) + len(right) len(left) len left len(right) len right left = merge_sort(left) left merge_sort(left) merge_sort left right = merge_sort(right) right merge_sort(right) merge_sort right return merge(left, right) merge(left, right) merge left right array array def merge(left, right):
    list = []
    l_index, r_index = 0, 0
    while l_index < len(left) and r_index < len(right):
        if left[l_index] <= right[r_index]:
            list.append(left[l_index])
            l_index += 1
        else:
            list.append(right[r_index])
            r_index += 1
    if l_index < len(left):
        list.extend(left[l_index:])
    if r_index < len(right):
        list.extend(right[r_index:])
    
    return list merge list = [] list [] l_index, r_index = 0, 0 l_index 0 r_index 0 while l_index < len(left) and r_index < len(right):
        if left[l_index] <= right[r_index]:
            list.append(left[l_index])
            l_index += 1
        else:
            list.append(right[r_index])
            r_index += 1
     l_index < len(left) and r_index < len(right) l_index < len(left) l_index len(left) len left r_index < len(right) r_index len(right) len right if left[l_index] <= right[r_index]:
            list.append(left[l_index])
            l_index += 1
        else:
            list.append(right[r_index])
            r_index += 1
     left[l_index] <= right[r_index] left[l_index] left l_index right[r_index] right r_index list.append(left[l_index]) list.append list append left[l_index] left l_index l_index += 1 l_index 1 list.append(right[r_index]) list.append list append right[r_index] right r_index r_index += 1 r_index 1 if l_index < len(left):
        list.extend(left[l_index:])
     l_index < len(left) l_index len(left) len left list.extend(left[l_index:]) list.extend list extend left[l_index:] left l_index: l_index if r_index < len(right):
        list.extend(right[r_index:])
    
     r_index < len(right) r_index len(right) len right list.extend(right[r_index:]) list.extend list extend right[r_index:] right r_index: r_index return list list left left right right 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 array = merge_sort(S) array merge_sort(S) merge_sort S print(" ".join(map(str, array))) print " ".join(map(str, array)) " ".join " " join map(str, array) map str array print(cnt) print cnt n = int(input()) int(input()) n cnt = 0 0 cnt def merge_sort(array):
    global cnt
    if len(array) <= 1:
        return array
    mid = len(array) // 2
    left = array[:mid]
    right = array[mid:]
    cnt += len(left) + len(right)
    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right) def merge_sort(array):
    global cnt
    if len(array) <= 1:
        return array
    mid = len(array) // 2
    left = array[:mid]
    right = array[mid:]
    cnt += len(left) + len(right)
    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right) merge_sort S = list(map(int, input().split())) list(map(int, input().split())) S array = merge_sort(S) merge_sort(S) array def merge(left, right):
    list = []
    l_index, r_index = 0, 0
    while l_index < len(left) and r_index < len(right):
        if left[l_index] <= right[r_index]:
            list.append(left[l_index])
            l_index += 1
        else:
            list.append(right[r_index])
            r_index += 1
    if l_index < len(left):
        list.extend(left[l_index:])
    if r_index < len(right):
        list.extend(right[r_index:])
    
    return list def merge(left, right):
    list = []
    l_index, r_index = 0, 0
    while l_index < len(left) and r_index < len(right):
        if left[l_index] <= right[r_index]:
            list.append(left[l_index])
            l_index += 1
        else:
            list.append(right[r_index])
            r_index += 1
    if l_index < len(left):
        list.extend(left[l_index:])
    if r_index < len(right):
        list.extend(right[r_index:])
    
    return list merge
cnt = 0
def merge_sort(array):
    global cnt
    if len(array) <= 1:
        return array
    mid = len(array) // 2
    left = array[:mid]
    right = array[mid:]
    cnt += len(left) + len(right)
    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right)

def merge(left, right):
    list = []
    l_index, r_index = 0, 0
    while l_index < len(left) and r_index < len(right):
        if left[l_index] <= right[r_index]:
            list.append(left[l_index])
            l_index += 1
        else:
            list.append(right[r_index])
            r_index += 1
    if l_index < len(left):
        list.extend(left[l_index:])
    if r_index < len(right):
        list.extend(right[r_index:])
    
    return list

n = int(input())
S = list(map(int, input().split()))
array = merge_sort(S)
print(" ".join(map(str, array)))
print(cnt)
