# coding=utf-8
def merge(a, left, mid, right):
    n1 = mid-left
    n2 = right - mid

    left_list = [a[left + i] for i in range(n1)]
    right_list = [a[mid + i] for i in range(n2)]
    left_list.append(1000000007)
    right_list.append(1000000007)

    i = 0
    j = 0
    ctr = 0
    for k in range(left, right):
        ctr += 1
        if left_list[i] <= right_list[j]:
            a[k] = left_list[i]
            i += 1
        else:
            a[k] = right_list[j]
            j += 1
    return ctr


def merge_sort(a, left, right, counter):
    if left+1 < right:
        mid = (left + right)//2
        counter1 = merge_sort(a, left, mid, counter)[1]
        counter2 = merge_sort(a, mid, right, counter)[1]
        counter += merge(a, left, mid, right)
        counter += counter1
        counter += counter2
    return a, counter


if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    merge_counter = 0
    S, merge_counter = merge_sort(S[:], 0, len(S), merge_counter)

    print(' '.join(map(str, S)))
    print(merge_counter) def merge(a, left, mid, right):
    n1 = mid-left
    n2 = right - mid

    left_list = [a[left + i] for i in range(n1)]
    right_list = [a[mid + i] for i in range(n2)]
    left_list.append(1000000007)
    right_list.append(1000000007)

    i = 0
    j = 0
    ctr = 0
    for k in range(left, right):
        ctr += 1
        if left_list[i] <= right_list[j]:
            a[k] = left_list[i]
            i += 1
        else:
            a[k] = right_list[j]
            j += 1
    return ctr merge n1 = mid-left n1 mid-left mid left n2 = right - mid n2 right - mid right mid a[left + i] for i in range(n1) for i in range(n1) i range(n1) range n1 for i in range(n1) a[left + i] a left + i left i left_list = [a[left + i] for i in range(n1)] left_list [a[left + i] for i in range(n1)] a[mid + i] for i in range(n2) for i in range(n2) i range(n2) range n2 for i in range(n2) a[mid + i] a mid + i mid i right_list = [a[mid + i] for i in range(n2)] right_list [a[mid + i] for i in range(n2)] left_list.append(1000000007) left_list.append left_list append 1000000007 right_list.append(1000000007) right_list.append right_list append 1000000007 i = 0 i 0 j = 0 j 0 ctr = 0 ctr 0 for k in range(left, right):
        ctr += 1
        if left_list[i] <= right_list[j]:
            a[k] = left_list[i]
            i += 1
        else:
            a[k] = right_list[j]
            j += 1
     k range(left, right) range left right ctr += 1 ctr 1 if left_list[i] <= right_list[j]:
            a[k] = left_list[i]
            i += 1
        else:
            a[k] = right_list[j]
            j += 1
     left_list[i] <= right_list[j] left_list[i] left_list i right_list[j] right_list j a[k] = left_list[i] a[k] a k left_list[i] left_list i i += 1 i 1 a[k] = right_list[j] a[k] a k right_list[j] right_list j j += 1 j 1 return ctr ctr a a left left mid mid right right def merge_sort(a, left, right, counter):
    if left+1 < right:
        mid = (left + right)//2
        counter1 = merge_sort(a, left, mid, counter)[1]
        counter2 = merge_sort(a, mid, right, counter)[1]
        counter += merge(a, left, mid, right)
        counter += counter1
        counter += counter2
    return a, counter merge_sort if left+1 < right:
        mid = (left + right)//2
        counter1 = merge_sort(a, left, mid, counter)[1]
        counter2 = merge_sort(a, mid, right, counter)[1]
        counter += merge(a, left, mid, right)
        counter += counter1
        counter += counter2
     left+1 < right left+1 left 1 right mid = (left + right)//2 mid (left + right)//2 left + right left right 2 counter1 = merge_sort(a, left, mid, counter)[1] counter1 merge_sort(a, left, mid, counter)[1] (a, left, mid, counter) merge_sort a left mid counter 1 counter2 = merge_sort(a, mid, right, counter)[1] counter2 merge_sort(a, mid, right, counter)[1] (a, mid, right, counter) merge_sort a mid right counter 1 counter += merge(a, left, mid, right) counter merge(a, left, mid, right) merge a left mid right counter += counter1 counter counter1 counter += counter2 counter counter2 return a, counter return a, counter a counter a a left left right right counter counter if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    merge_counter = 0
    S, merge_counter = merge_sort(S[:], 0, len(S), merge_counter)

    print(' '.join(map(str, S)))
    print(merge_counter) __name__ == '__main__' __name__ '__main__' 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 merge_counter = 0 merge_counter 0 S, merge_counter = merge_sort(S[:], 0, len(S), merge_counter) S merge_sort(S[:], 0, len(S), merge_counter) merge_sort S[:] S : 0 len(S) len S merge_counter merge_counter print(' '.join(map(str, S))) print ' '.join(map(str, S)) ' '.join ' ' join map(str, S) map str S print(merge_counter) print merge_counter def merge_sort(a, left, right, counter):
    if left+1 < right:
        mid = (left + right)//2
        counter1 = merge_sort(a, left, mid, counter)[1]
        counter2 = merge_sort(a, mid, right, counter)[1]
        counter += merge(a, left, mid, right)
        counter += counter1
        counter += counter2
    return a, counter def merge_sort(a, left, right, counter):
    if left+1 < right:
        mid = (left + right)//2
        counter1 = merge_sort(a, left, mid, counter)[1]
        counter2 = merge_sort(a, mid, right, counter)[1]
        counter += merge(a, left, mid, right)
        counter += counter1
        counter += counter2
    return a, counter merge_sort def merge(a, left, mid, right):
    n1 = mid-left
    n2 = right - mid

    left_list = [a[left + i] for i in range(n1)]
    right_list = [a[mid + i] for i in range(n2)]
    left_list.append(1000000007)
    right_list.append(1000000007)

    i = 0
    j = 0
    ctr = 0
    for k in range(left, right):
        ctr += 1
        if left_list[i] <= right_list[j]:
            a[k] = left_list[i]
            i += 1
        else:
            a[k] = right_list[j]
            j += 1
    return ctr def merge(a, left, mid, right):
    n1 = mid-left
    n2 = right - mid

    left_list = [a[left + i] for i in range(n1)]
    right_list = [a[mid + i] for i in range(n2)]
    left_list.append(1000000007)
    right_list.append(1000000007)

    i = 0
    j = 0
    ctr = 0
    for k in range(left, right):
        ctr += 1
        if left_list[i] <= right_list[j]:
            a[k] = left_list[i]
            i += 1
        else:
            a[k] = right_list[j]
            j += 1
    return ctr merge S = list(map(int, input().split())) list(map(int, input().split())) S merge_counter = 0 0 merge_counter merge_counter = merge_sort(S[:], 0, len(S), merge_counter) merge_sort(S[:], 0, len(S), merge_counter) merge_counter n = int(input()) int(input()) n S, merge_counter = merge_sort(S[:], 0, len(S), merge_counter) merge_sort(S[:], 0, len(S), merge_counter) S
# coding=utf-8
def merge(a, left, mid, right):
    n1 = mid-left
    n2 = right - mid

    left_list = [a[left + i] for i in range(n1)]
    right_list = [a[mid + i] for i in range(n2)]
    left_list.append(1000000007)
    right_list.append(1000000007)

    i = 0
    j = 0
    ctr = 0
    for k in range(left, right):
        ctr += 1
        if left_list[i] <= right_list[j]:
            a[k] = left_list[i]
            i += 1
        else:
            a[k] = right_list[j]
            j += 1
    return ctr


def merge_sort(a, left, right, counter):
    if left+1 < right:
        mid = (left + right)//2
        counter1 = merge_sort(a, left, mid, counter)[1]
        counter2 = merge_sort(a, mid, right, counter)[1]
        counter += merge(a, left, mid, right)
        counter += counter1
        counter += counter2
    return a, counter


if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    merge_counter = 0
    S, merge_counter = merge_sort(S[:], 0, len(S), merge_counter)

    print(' '.join(map(str, S)))
    print(merge_counter)