counter = 0


def merge(A, left, mid, right):
    m = mid - left
    n = right - mid
    L = [None] * (m+1)
    R = [None] * (n+2)

    for i in range(m):
        L[i] = A[left + i]

    for i in range(n):
        R[i] = A[mid + i]

    L[m], R[n] = float("inf"), float("inf")  # stoper
    i, j = 0, 0

    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global counter
    counter += right - left
    return


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)
    return A


def main():
    _ = input()
    A = [int(i) for i in input().strip().split()]
    merge_sort(A, 0, len(A))
    print(" ".join([str(i) for i in A]))


if __name__ == "__main__":
    counter = 0
    main()
    print(counter)
 counter = 0 counter 0 def merge(A, left, mid, right):
    m = mid - left
    n = right - mid
    L = [None] * (m+1)
    R = [None] * (n+2)

    for i in range(m):
        L[i] = A[left + i]

    for i in range(n):
        R[i] = A[mid + i]

    L[m], R[n] = float("inf"), float("inf")  # stoper
    i, j = 0, 0

    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global counter
    counter += right - left
    return merge m = mid - left m mid - left mid left n = right - mid n right - mid right mid L = [None] * (m+1) L [None] * (m+1) [None] None m+1 m 1 R = [None] * (n+2) R [None] * (n+2) [None] None n+2 n 2 for i in range(m):
        L[i] = A[left + i]

     i range(m) range m L[i] = A[left + i] L[i] L i A[left + i] A left + i left i for i in range(n):
        R[i] = A[mid + i]

     i range(n) range n R[i] = A[mid + i] R[i] R i A[mid + i] A mid + i mid i L[m], R[n] = float("inf"), float("inf") L[m] L m float("inf") float "inf" R[n] R n float("inf") float "inf" i, j = 0, 0 i 0 j 0 for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
     k range(left, right) range left right if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
     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 global counter counter += right - left counter right - left right left return A A left left mid mid right right def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)
    return A merge_sort 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 return A A A A left left right right def main():
    _ = input()
    A = [int(i) for i in input().strip().split()]
    merge_sort(A, 0, len(A))
    print(" ".join([str(i) for i in A])) main _ = input() _ input() input int(i) for i in input().strip().split() for i in input().strip().split() i input().strip().split() ().strip().split ().strip() ().strip () input strip split for i in input().strip().split() int(i) int i A = [int(i) for i in input().strip().split()] A [int(i) for i in input().strip().split()] merge_sort(A, 0, len(A)) merge_sort A 0 len(A) len A str(i) for i in A for i in A i A for i in A str(i) str i print(" ".join([str(i) for i in A])) print " ".join([str(i) for i in A]) " ".join " " join [str(i) for i in A] if __name__ == "__main__":
    counter = 0
    main()
    print(counter) __name__ == "__main__" __name__ "__main__" counter = 0 counter 0 main() main print(counter) print counter counter = 0 0 counter def main():
    _ = input()
    A = [int(i) for i in input().strip().split()]
    merge_sort(A, 0, len(A))
    print(" ".join([str(i) for i in A])) def main():
    _ = input()
    A = [int(i) for i in input().strip().split()]
    merge_sort(A, 0, len(A))
    print(" ".join([str(i) for i in A])) main counter = 0 0 counter def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)
    return A def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)
    return A merge_sort def merge(A, left, mid, right):
    m = mid - left
    n = right - mid
    L = [None] * (m+1)
    R = [None] * (n+2)

    for i in range(m):
        L[i] = A[left + i]

    for i in range(n):
        R[i] = A[mid + i]

    L[m], R[n] = float("inf"), float("inf")  # stoper
    i, j = 0, 0

    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global counter
    counter += right - left
    return def merge(A, left, mid, right):
    m = mid - left
    n = right - mid
    L = [None] * (m+1)
    R = [None] * (n+2)

    for i in range(m):
        L[i] = A[left + i]

    for i in range(n):
        R[i] = A[mid + i]

    L[m], R[n] = float("inf"), float("inf")  # stoper
    i, j = 0, 0

    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global counter
    counter += right - left
    return merge
counter = 0


def merge(A, left, mid, right):
    m = mid - left
    n = right - mid
    L = [None] * (m+1)
    R = [None] * (n+2)

    for i in range(m):
        L[i] = A[left + i]

    for i in range(n):
        R[i] = A[mid + i]

    L[m], R[n] = float("inf"), float("inf")  # stoper
    i, j = 0, 0

    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    global counter
    counter += right - left
    return


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)
    return A


def main():
    _ = input()
    A = [int(i) for i in input().strip().split()]
    merge_sort(A, 0, len(A))
    print(" ".join([str(i) for i in A]))


if __name__ == "__main__":
    counter = 0
    main()
    print(counter)

