def merge(a, left, mid, right):
    """ merge list a[left:mid] and a[mid:right], assuming the lists is sorted
    """
    global cnt
    inf = 10 ** 9
    left_a = a[left:mid] + [inf]
    right_a = a[mid:right] + [inf]
    
    i, j = 0, 0

    for k in range(left, right):
        if left_a[i] <= right_a[j]:
            a[k] = left_a[i]
            i += 1
        else:
            a[k] = right_a[j]
            j += 1

        cnt += 1


def merge_sort(a, left, right):
    """ split list a[left:right-1] into two lists and merge
    """
    if left + 1 < right:
        mid = (left + right)//2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

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

print(' '.join(str(n) for n in a))
print(cnt) def merge(a, left, mid, right):
    """ merge list a[left:mid] and a[mid:right], assuming the lists is sorted
    """
    global cnt
    inf = 10 ** 9
    left_a = a[left:mid] + [inf]
    right_a = a[mid:right] + [inf]
    
    i, j = 0, 0

    for k in range(left, right):
        if left_a[i] <= right_a[j]:
            a[k] = left_a[i]
            i += 1
        else:
            a[k] = right_a[j]
            j += 1

        cnt += 1 merge """ merge list a[left:mid] and a[mid:right], assuming the lists is sorted
    """ global cnt inf = 10 ** 9 inf 10 ** 9 10 9 left_a = a[left:mid] + [inf] left_a a[left:mid] + [inf] a[left:mid] a left:mid left mid [inf] inf right_a = a[mid:right] + [inf] right_a a[mid:right] + [inf] a[mid:right] a mid:right mid right [inf] inf i, j = 0, 0 i 0 j 0 for k in range(left, right):
        if left_a[i] <= right_a[j]:
            a[k] = left_a[i]
            i += 1
        else:
            a[k] = right_a[j]
            j += 1

        cnt += 1 k range(left, right) range left right if left_a[i] <= right_a[j]:
            a[k] = left_a[i]
            i += 1
        else:
            a[k] = right_a[j]
            j += 1

         left_a[i] <= right_a[j] left_a[i] left_a i right_a[j] right_a j a[k] = left_a[i] a[k] a k left_a[i] left_a i i += 1 i 1 a[k] = right_a[j] a[k] a k right_a[j] right_a j j += 1 j 1 cnt += 1 cnt 1 a a left left mid mid right right def merge_sort(a, left, right):
    """ split list a[left:right-1] into two lists and merge
    """
    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 """ split list a[left:right-1] into two lists and merge
    """ 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 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 cnt = 0 cnt 0 merge_sort(a, 0, n) merge_sort a 0 n print(' '.join(str(n) for n in a)) print ' '.join(str(n) for n in a) ' '.join ' ' join str(n) str n print(cnt) print cnt cnt = 0 0 cnt def merge(a, left, mid, right):
    """ merge list a[left:mid] and a[mid:right], assuming the lists is sorted
    """
    global cnt
    inf = 10 ** 9
    left_a = a[left:mid] + [inf]
    right_a = a[mid:right] + [inf]
    
    i, j = 0, 0

    for k in range(left, right):
        if left_a[i] <= right_a[j]:
            a[k] = left_a[i]
            i += 1
        else:
            a[k] = right_a[j]
            j += 1

        cnt += 1 def merge(a, left, mid, right):
    """ merge list a[left:mid] and a[mid:right], assuming the lists is sorted
    """
    global cnt
    inf = 10 ** 9
    left_a = a[left:mid] + [inf]
    right_a = a[mid:right] + [inf]
    
    i, j = 0, 0

    for k in range(left, right):
        if left_a[i] <= right_a[j]:
            a[k] = left_a[i]
            i += 1
        else:
            a[k] = right_a[j]
            j += 1

        cnt += 1 merge n = int(input()) int(input()) n a = list(map(int, input().split())) list(map(int, input().split())) a def merge_sort(a, left, right):
    """ split list a[left:right-1] into two lists and merge
    """
    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):
    """ split list a[left:right-1] into two lists and merge
    """
    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):
    """ merge list a[left:mid] and a[mid:right], assuming the lists is sorted
    """
    global cnt
    inf = 10 ** 9
    left_a = a[left:mid] + [inf]
    right_a = a[mid:right] + [inf]
    
    i, j = 0, 0

    for k in range(left, right):
        if left_a[i] <= right_a[j]:
            a[k] = left_a[i]
            i += 1
        else:
            a[k] = right_a[j]
            j += 1

        cnt += 1


def merge_sort(a, left, right):
    """ split list a[left:right-1] into two lists and merge
    """
    if left + 1 < right:
        mid = (left + right)//2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

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

print(' '.join(str(n) for n in a))
print(cnt)
