import math


def merge(S, left, mid, right) -> int:
    # n1 = mid - left
    # n2 = right - mid
    L = S[left: mid]
    R = S[mid: right]

    # for i in range(n1):
    #     L.append(S[left + i])
    L.append(math.inf)

    # for i in range(n2):
    #     R.append(S[mid + i])
    R.append(math.inf)

    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

    return right - left


def merge_sort(S, left, right):
    count = 0

    if left + 1 < right:
        mid = int((left + right) / 2)
        count += merge_sort(S, left, mid)
        count += merge_sort(S, mid, right)
        count += merge(S, left, mid, right)

    return count


def main():
    n = int(input())
    S = list(map(int, input().split()))
    count = 0

    count = merge_sort(S, 0, n)

    print(*S)
    print(count)


if __name__ == "__main__":
    main()
 import math math def merge(S, left, mid, right) -> int:
    # n1 = mid - left
    # n2 = right - mid
    L = S[left: mid]
    R = S[mid: right]

    # for i in range(n1):
    #     L.append(S[left + i])
    L.append(math.inf)

    # for i in range(n2):
    #     R.append(S[mid + i])
    R.append(math.inf)

    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

    return right - left merge L = S[left: mid] L S[left: mid] S left: mid left mid R = S[mid: right] R S[mid: right] S mid: right mid right L.append(math.inf) L.append L append math.inf math inf R.append(math.inf) R.append R append math.inf math inf i = 0 i 0 j = 0 j 0 for k in range(left, right):
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

     k range(left, right) range left right if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

     L[i] <= R[j] L[i] L i R[j] R j S[k] = L[i] S[k] S k L[i] L i i += 1 i 1 S[k] = R[j] S[k] S k R[j] R j j += 1 j 1 return right - left right - left right left S S left left mid mid right right def merge_sort(S, left, right):
    count = 0

    if left + 1 < right:
        mid = int((left + right) / 2)
        count += merge_sort(S, left, mid)
        count += merge_sort(S, mid, right)
        count += merge(S, left, mid, right)

    return count merge_sort count = 0 count 0 if left + 1 < right:
        mid = int((left + right) / 2)
        count += merge_sort(S, left, mid)
        count += merge_sort(S, mid, right)
        count += merge(S, left, mid, right)

     left + 1 < right left + 1 left 1 right mid = int((left + right) / 2) mid int((left + right) / 2) int (left + right) / 2 left + right left right 2 count += merge_sort(S, left, mid) count merge_sort(S, left, mid) merge_sort S left mid count += merge_sort(S, mid, right) count merge_sort(S, mid, right) merge_sort S mid right count += merge(S, left, mid, right) count merge(S, left, mid, right) merge S left mid right return count count S S left left right right def main():
    n = int(input())
    S = list(map(int, input().split()))
    count = 0

    count = merge_sort(S, 0, n)

    print(*S)
    print(count) 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 count = 0 count 0 count = merge_sort(S, 0, n) count merge_sort(S, 0, n) merge_sort S 0 n print(*S) print *S S print(count) print count if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n = int(input())
    S = list(map(int, input().split()))
    count = 0

    count = merge_sort(S, 0, n)

    print(*S)
    print(count) def main():
    n = int(input())
    S = list(map(int, input().split()))
    count = 0

    count = merge_sort(S, 0, n)

    print(*S)
    print(count) main def merge(S, left, mid, right) -> int:
    # n1 = mid - left
    # n2 = right - mid
    L = S[left: mid]
    R = S[mid: right]

    # for i in range(n1):
    #     L.append(S[left + i])
    L.append(math.inf)

    # for i in range(n2):
    #     R.append(S[mid + i])
    R.append(math.inf)

    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

    return right - left def merge(S, left, mid, right) -> int:
    # n1 = mid - left
    # n2 = right - mid
    L = S[left: mid]
    R = S[mid: right]

    # for i in range(n1):
    #     L.append(S[left + i])
    L.append(math.inf)

    # for i in range(n2):
    #     R.append(S[mid + i])
    R.append(math.inf)

    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

    return right - left merge def merge_sort(S, left, right):
    count = 0

    if left + 1 < right:
        mid = int((left + right) / 2)
        count += merge_sort(S, left, mid)
        count += merge_sort(S, mid, right)
        count += merge(S, left, mid, right)

    return count def merge_sort(S, left, right):
    count = 0

    if left + 1 < right:
        mid = int((left + right) / 2)
        count += merge_sort(S, left, mid)
        count += merge_sort(S, mid, right)
        count += merge(S, left, mid, right)

    return count merge_sort
import math


def merge(S, left, mid, right) -> int:
    # n1 = mid - left
    # n2 = right - mid
    L = S[left: mid]
    R = S[mid: right]

    # for i in range(n1):
    #     L.append(S[left + i])
    L.append(math.inf)

    # for i in range(n2):
    #     R.append(S[mid + i])
    R.append(math.inf)

    i = 0
    j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1

    return right - left


def merge_sort(S, left, right):
    count = 0

    if left + 1 < right:
        mid = int((left + right) / 2)
        count += merge_sort(S, left, mid)
        count += merge_sort(S, mid, right)
        count += merge(S, left, mid, right)

    return count


def main():
    n = int(input())
    S = list(map(int, input().split()))
    count = 0

    count = merge_sort(S, 0, n)

    print(*S)
    print(count)


if __name__ == "__main__":
    main()

