import sys
input = sys.stdin.readline

n = int(input())
S = list(map(int, input().split()))
SENTINEL = 1000000005
merge_count = 0


def main():
    mergeSort(S, 0, len(S))
    print(' '.join(map(str, S)))
    print(merge_count)


def merge(A, left, mid, right):
    # print("---merge start---")
    # print("A is {}".format(A))
    # print("left:{0}, mid:{1}, right{2}".format(left, mid, right))
    global merge_count

    L = A[left:mid] + [SENTINEL]
    R = A[mid:right] + [SENTINEL]

    # print("L:{}".format(L))
    # print("R:{}".format(R))

    i, j = 0, 0
    for k in range(left, right, 1):
        merge_count += 1
        # print("k:{0}".format(k))
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    # print("A is {}".format(A))
    # print("----merge end----".format(A))


def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        # print("------mergeSort start--------")
        # print("left:{0}, mid:{1}, right:{2}".format(left, mid, right))
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)


if __name__ == '__main__':
    main()
 import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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 SENTINEL = 1000000005 SENTINEL 1000000005 merge_count = 0 merge_count 0 def main():
    mergeSort(S, 0, len(S))
    print(' '.join(map(str, S)))
    print(merge_count) main mergeSort(S, 0, len(S)) mergeSort S 0 len(S) len S print(' '.join(map(str, S))) print ' '.join(map(str, S)) ' '.join ' ' join map(str, S) map str S print(merge_count) print merge_count def merge(A, left, mid, right):
    # print("---merge start---")
    # print("A is {}".format(A))
    # print("left:{0}, mid:{1}, right{2}".format(left, mid, right))
    global merge_count

    L = A[left:mid] + [SENTINEL]
    R = A[mid:right] + [SENTINEL]

    # print("L:{}".format(L))
    # print("R:{}".format(R))

    i, j = 0, 0
    for k in range(left, right, 1):
        merge_count += 1
        # print("k:{0}".format(k))
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    # print("A is {}".format(A))
    # print("----merge end----".format(A)) merge global merge_count L = A[left:mid] + [SENTINEL] L A[left:mid] + [SENTINEL] A[left:mid] A left:mid left mid [SENTINEL] SENTINEL R = A[mid:right] + [SENTINEL] R A[mid:right] + [SENTINEL] A[mid:right] A mid:right mid right [SENTINEL] SENTINEL i, j = 0, 0 i 0 j 0 for k in range(left, right, 1):
        merge_count += 1
        # print("k:{0}".format(k))
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    # print("A is {}".format(A))
    # print("----merge end----".format(A)) k range(left, right, 1) range left right 1 merge_count += 1 merge_count 1 if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    # print("A is {}".format(A))
    # print("----merge end----".format(A)) L[i] <= R[j] L[i] L i R[j] R j A[k] = L[i] A[k] A k L[i] L i i += 1 i 1 A[k] = R[j] A[k] A k R[j] R j j += 1 j 1 A A left left mid mid right right def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        # print("------mergeSort start--------")
        # print("left:{0}, mid:{1}, right:{2}".format(left, mid, right))
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right) mergeSort if left + 1 < right:
        mid = (left + right) // 2
        # print("------mergeSort start--------")
        # print("left:{0}, mid:{1}, right:{2}".format(left, mid, right))
        mergeSort(A, left, mid)
        mergeSort(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 mergeSort(A, left, mid) mergeSort A left mid mergeSort(A, mid, right) mergeSort A mid right merge(A, left, mid, right) merge A left mid right A A left left right right if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def merge(A, left, mid, right):
    # print("---merge start---")
    # print("A is {}".format(A))
    # print("left:{0}, mid:{1}, right{2}".format(left, mid, right))
    global merge_count

    L = A[left:mid] + [SENTINEL]
    R = A[mid:right] + [SENTINEL]

    # print("L:{}".format(L))
    # print("R:{}".format(R))

    i, j = 0, 0
    for k in range(left, right, 1):
        merge_count += 1
        # print("k:{0}".format(k))
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    # print("A is {}".format(A))
    # print("----merge end----".format(A)) def merge(A, left, mid, right):
    # print("---merge start---")
    # print("A is {}".format(A))
    # print("left:{0}, mid:{1}, right{2}".format(left, mid, right))
    global merge_count

    L = A[left:mid] + [SENTINEL]
    R = A[mid:right] + [SENTINEL]

    # print("L:{}".format(L))
    # print("R:{}".format(R))

    i, j = 0, 0
    for k in range(left, right, 1):
        merge_count += 1
        # print("k:{0}".format(k))
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    # print("A is {}".format(A))
    # print("----merge end----".format(A)) merge input = sys.stdin.readline sys.stdin.readline input merge_count = 0 0 merge_count def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        # print("------mergeSort start--------")
        # print("left:{0}, mid:{1}, right:{2}".format(left, mid, right))
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right) def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        # print("------mergeSort start--------")
        # print("left:{0}, mid:{1}, right:{2}".format(left, mid, right))
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right) mergeSort SENTINEL = 1000000005 1000000005 SENTINEL n = int(input()) int(input()) n S = list(map(int, input().split())) list(map(int, input().split())) S def main():
    mergeSort(S, 0, len(S))
    print(' '.join(map(str, S)))
    print(merge_count) def main():
    mergeSort(S, 0, len(S))
    print(' '.join(map(str, S)))
    print(merge_count) main
import sys
input = sys.stdin.readline

n = int(input())
S = list(map(int, input().split()))
SENTINEL = 1000000005
merge_count = 0


def main():
    mergeSort(S, 0, len(S))
    print(' '.join(map(str, S)))
    print(merge_count)


def merge(A, left, mid, right):
    # print("---merge start---")
    # print("A is {}".format(A))
    # print("left:{0}, mid:{1}, right{2}".format(left, mid, right))
    global merge_count

    L = A[left:mid] + [SENTINEL]
    R = A[mid:right] + [SENTINEL]

    # print("L:{}".format(L))
    # print("R:{}".format(R))

    i, j = 0, 0
    for k in range(left, right, 1):
        merge_count += 1
        # print("k:{0}".format(k))
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    # print("A is {}".format(A))
    # print("----merge end----".format(A))


def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        # print("------mergeSort start--------")
        # print("left:{0}, mid:{1}, right:{2}".format(left, mid, right))
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)


if __name__ == '__main__':
    main()

