global count


def merge(arr, l, mid, r):
    arr_l = list(arr[l:mid + 1])
    arr_r = list(arr[mid + 1:r + 1])
    l_index = 0
    r_index = 0
    arr_l.append(2 << 64)
    arr_r.append(2 << 64)
    global count
    for i in range(l, r + 1):
        if arr_l[l_index] <= arr_r[r_index]:
            arr[i] = arr_l[l_index]
            l_index += 1
        else:
            arr[i] = arr_r[r_index]
            r_index += 1
        count += 1


def merge_sort(arr, l, r):
    if l >= r:
        return
    mid = (l + r) // 2
    merge_sort(arr, l, mid)
    merge_sort(arr, mid + 1, r)
    merge(arr, l, mid, r)


if __name__ == '__main__':
    count = 0

    n = int(input())
    arr = list(map(int, input().split()))
    merge_sort(arr, 0, len(arr) - 1)
    for i in range(n):
        if i != n - 1:
            print(arr[i], end=' ')
        else:
            print(arr[i])
    print(count)
 global count def merge(arr, l, mid, r):
    arr_l = list(arr[l:mid + 1])
    arr_r = list(arr[mid + 1:r + 1])
    l_index = 0
    r_index = 0
    arr_l.append(2 << 64)
    arr_r.append(2 << 64)
    global count
    for i in range(l, r + 1):
        if arr_l[l_index] <= arr_r[r_index]:
            arr[i] = arr_l[l_index]
            l_index += 1
        else:
            arr[i] = arr_r[r_index]
            r_index += 1
        count += 1 merge arr_l = list(arr[l:mid + 1]) arr_l list(arr[l:mid + 1]) list arr[l:mid + 1] arr l:mid + 1 l mid + 1 mid 1 arr_r = list(arr[mid + 1:r + 1]) arr_r list(arr[mid + 1:r + 1]) list arr[mid + 1:r + 1] arr mid + 1:r + 1 mid + 1 mid 1 r + 1 r 1 l_index = 0 l_index 0 r_index = 0 r_index 0 arr_l.append(2 << 64) arr_l.append arr_l append 2 << 64 2 64 arr_r.append(2 << 64) arr_r.append arr_r append 2 << 64 2 64 global count for i in range(l, r + 1):
        if arr_l[l_index] <= arr_r[r_index]:
            arr[i] = arr_l[l_index]
            l_index += 1
        else:
            arr[i] = arr_r[r_index]
            r_index += 1
        count += 1 i range(l, r + 1) range l r + 1 r 1 if arr_l[l_index] <= arr_r[r_index]:
            arr[i] = arr_l[l_index]
            l_index += 1
        else:
            arr[i] = arr_r[r_index]
            r_index += 1
         arr_l[l_index] <= arr_r[r_index] arr_l[l_index] arr_l l_index arr_r[r_index] arr_r r_index arr[i] = arr_l[l_index] arr[i] arr i arr_l[l_index] arr_l l_index l_index += 1 l_index 1 arr[i] = arr_r[r_index] arr[i] arr i arr_r[r_index] arr_r r_index r_index += 1 r_index 1 count += 1 count 1 arr arr l l mid mid r r def merge_sort(arr, l, r):
    if l >= r:
        return
    mid = (l + r) // 2
    merge_sort(arr, l, mid)
    merge_sort(arr, mid + 1, r)
    merge(arr, l, mid, r) merge_sort if l >= r:
        return
     l >= r l r return mid = (l + r) // 2 mid (l + r) // 2 l + r l r 2 merge_sort(arr, l, mid) merge_sort arr l mid merge_sort(arr, mid + 1, r) merge_sort arr mid + 1 mid 1 r merge(arr, l, mid, r) merge arr l mid r arr arr l l r r if __name__ == '__main__':
    count = 0

    n = int(input())
    arr = list(map(int, input().split()))
    merge_sort(arr, 0, len(arr) - 1)
    for i in range(n):
        if i != n - 1:
            print(arr[i], end=' ')
        else:
            print(arr[i])
    print(count) __name__ == '__main__' __name__ '__main__' count = 0 count 0 n = int(input()) n int(input()) int input() input arr = list(map(int, input().split())) arr list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split merge_sort(arr, 0, len(arr) - 1) merge_sort arr 0 len(arr) - 1 len(arr) len arr 1 for i in range(n):
        if i != n - 1:
            print(arr[i], end=' ')
        else:
            print(arr[i])
     i range(n) range n if i != n - 1:
            print(arr[i], end=' ')
        else:
            print(arr[i])
     i != n - 1 i n - 1 n 1 print(arr[i], end=' ') print arr[i] arr i end=' ' end ' ' print(arr[i]) print arr[i] arr i print(count) print count def merge_sort(arr, l, r):
    if l >= r:
        return
    mid = (l + r) // 2
    merge_sort(arr, l, mid)
    merge_sort(arr, mid + 1, r)
    merge(arr, l, mid, r) def merge_sort(arr, l, r):
    if l >= r:
        return
    mid = (l + r) // 2
    merge_sort(arr, l, mid)
    merge_sort(arr, mid + 1, r)
    merge(arr, l, mid, r) merge_sort n = int(input()) int(input()) n global count arr = list(map(int, input().split())) list(map(int, input().split())) arr count = 0 0 count def merge(arr, l, mid, r):
    arr_l = list(arr[l:mid + 1])
    arr_r = list(arr[mid + 1:r + 1])
    l_index = 0
    r_index = 0
    arr_l.append(2 << 64)
    arr_r.append(2 << 64)
    global count
    for i in range(l, r + 1):
        if arr_l[l_index] <= arr_r[r_index]:
            arr[i] = arr_l[l_index]
            l_index += 1
        else:
            arr[i] = arr_r[r_index]
            r_index += 1
        count += 1 def merge(arr, l, mid, r):
    arr_l = list(arr[l:mid + 1])
    arr_r = list(arr[mid + 1:r + 1])
    l_index = 0
    r_index = 0
    arr_l.append(2 << 64)
    arr_r.append(2 << 64)
    global count
    for i in range(l, r + 1):
        if arr_l[l_index] <= arr_r[r_index]:
            arr[i] = arr_l[l_index]
            l_index += 1
        else:
            arr[i] = arr_r[r_index]
            r_index += 1
        count += 1 merge
global count


def merge(arr, l, mid, r):
    arr_l = list(arr[l:mid + 1])
    arr_r = list(arr[mid + 1:r + 1])
    l_index = 0
    r_index = 0
    arr_l.append(2 << 64)
    arr_r.append(2 << 64)
    global count
    for i in range(l, r + 1):
        if arr_l[l_index] <= arr_r[r_index]:
            arr[i] = arr_l[l_index]
            l_index += 1
        else:
            arr[i] = arr_r[r_index]
            r_index += 1
        count += 1


def merge_sort(arr, l, r):
    if l >= r:
        return
    mid = (l + r) // 2
    merge_sort(arr, l, mid)
    merge_sort(arr, mid + 1, r)
    merge(arr, l, mid, r)


if __name__ == '__main__':
    count = 0

    n = int(input())
    arr = list(map(int, input().split()))
    merge_sort(arr, 0, len(arr) - 1)
    for i in range(n):
        if i != n - 1:
            print(arr[i], end=' ')
        else:
            print(arr[i])
    print(count)

