def merge(A, left, mid, right):
    count = 0
    INF = 1000000000000000000000
    n1 = mid - left
    n2 = right - mid

    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]
    L.append(INF)
    R.append(INF)

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


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


def main():
    global A
    n = int(input())
    A = list(map(int, input().split()))
    count = merge_sort(A, 0, len(A))
    print(" ".join([str(a) for a in A]))
    print(count)

main()
 def merge(A, left, mid, right):
    count = 0
    INF = 1000000000000000000000
    n1 = mid - left
    n2 = right - mid

    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]
    L.append(INF)
    R.append(INF)

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return count merge count = 0 count 0 INF = 1000000000000000000000 INF 1000000000000000000000 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 L = [A[left+i] for i in range(n1)] L [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 R = [A[mid+i] for i in range(n2)] R [A[mid+i] for i in range(n2)] L.append(INF) L.append L append INF R.append(INF) R.append R append INF i, j = 0, 0 i 0 j 0 for k in range(left, right):
        count += 1
        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 count += 1 count 1 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 return count count A A left left mid mid right right def merge_sort(A, left, right):
    if left+1 < right:
        mid = (left + right) // 2
        count_left = merge_sort(A, left, mid)
        count_right = merge_sort(A, mid, right)
        count = merge(A, left, mid, right)
        return count + count_right + count_left
    return 0 merge_sort if left+1 < right:
        mid = (left + right) // 2
        count_left = merge_sort(A, left, mid)
        count_right = merge_sort(A, mid, right)
        count = merge(A, left, mid, right)
        return count + count_right + count_left
     left+1 < right left+1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 count_left = merge_sort(A, left, mid) count_left merge_sort(A, left, mid) merge_sort A left mid count_right = merge_sort(A, mid, right) count_right merge_sort(A, mid, right) merge_sort A mid right count = merge(A, left, mid, right) count merge(A, left, mid, right) merge A left mid right return count + count_right + count_left count + count_right + count_left count + count_right count count_right count_left return 0 0 A A left left right right def main():
    global A
    n = int(input())
    A = list(map(int, input().split()))
    count = merge_sort(A, 0, len(A))
    print(" ".join([str(a) for a in A]))
    print(count) main global A n = int(input()) n int(input()) int input() input A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split count = merge_sort(A, 0, len(A)) count merge_sort(A, 0, len(A)) merge_sort A 0 len(A) len A str(a) for a in A for a in A a A for a in A str(a) str a print(" ".join([str(a) for a in A])) print " ".join([str(a) for a in A]) " ".join " " join [str(a) for a in A] print(count) print count main() main def merge(A, left, mid, right):
    count = 0
    INF = 1000000000000000000000
    n1 = mid - left
    n2 = right - mid

    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]
    L.append(INF)
    R.append(INF)

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return count def merge(A, left, mid, right):
    count = 0
    INF = 1000000000000000000000
    n1 = mid - left
    n2 = right - mid

    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]
    L.append(INF)
    R.append(INF)

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return count merge def merge_sort(A, left, right):
    if left+1 < right:
        mid = (left + right) // 2
        count_left = merge_sort(A, left, mid)
        count_right = merge_sort(A, mid, right)
        count = merge(A, left, mid, right)
        return count + count_right + count_left
    return 0 def merge_sort(A, left, right):
    if left+1 < right:
        mid = (left + right) // 2
        count_left = merge_sort(A, left, mid)
        count_right = merge_sort(A, mid, right)
        count = merge(A, left, mid, right)
        return count + count_right + count_left
    return 0 merge_sort def main():
    global A
    n = int(input())
    A = list(map(int, input().split()))
    count = merge_sort(A, 0, len(A))
    print(" ".join([str(a) for a in A]))
    print(count) def main():
    global A
    n = int(input())
    A = list(map(int, input().split()))
    count = merge_sort(A, 0, len(A))
    print(" ".join([str(a) for a in A]))
    print(count) main
def merge(A, left, mid, right):
    count = 0
    INF = 1000000000000000000000
    n1 = mid - left
    n2 = right - mid

    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]
    L.append(INF)
    R.append(INF)

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


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


def main():
    global A
    n = int(input())
    A = list(map(int, input().split()))
    count = merge_sort(A, 0, len(A))
    print(" ".join([str(a) for a in A]))
    print(count)

main()

