def merge(A, left, mid, right, cnt):
    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(1e10)
    R.append(1e10)

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

    else:
        cnt.append(c)


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


def main():
    cnt = []
    _ = int(input())
    S = list(map(int, input().split()))
    mergeSort(S, 0, len(S), cnt)
    print(*S)
    print(sum(cnt))


if __name__ == "__main__":
    main()
 def merge(A, left, mid, right, cnt):
    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(1e10)
    R.append(1e10)

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

    else:
        cnt.append(c) 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 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(1e10) L.append L append 1e10 R.append(1e10) R.append R append 1e10 i = 0 i 0 j = 0 j 0 c = 0 c 0 for k in range(left, right):
        c += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1 
        else:
            A[k] = R[j]
            j += 1

    else:
        cnt.append(c) k range(left, right) range left right c += 1 c 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 cnt.append(c) cnt.append cnt append c A A left left mid mid right right cnt cnt def mergeSort(A, left, right, cnt):
    if left+1 < right:
        mid = (left+right) // 2
        mergeSort(A, left, mid, cnt)
        mergeSort(A, mid, right, cnt)
        merge(A, left, mid, right, cnt) mergeSort if left+1 < right:
        mid = (left+right) // 2
        mergeSort(A, left, mid, cnt)
        mergeSort(A, mid, right, cnt)
        merge(A, left, mid, right, cnt) 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, cnt) mergeSort A left mid cnt mergeSort(A, mid, right, cnt) mergeSort A mid right cnt merge(A, left, mid, right, cnt) merge A left mid right cnt A A left left right right cnt cnt def main():
    cnt = []
    _ = int(input())
    S = list(map(int, input().split()))
    mergeSort(S, 0, len(S), cnt)
    print(*S)
    print(sum(cnt)) main cnt = [] cnt [] _ = int(input()) _ 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 mergeSort(S, 0, len(S), cnt) mergeSort S 0 len(S) len S cnt print(*S) print *S S print(sum(cnt)) print sum(cnt) sum cnt if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def merge(A, left, mid, right, cnt):
    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(1e10)
    R.append(1e10)

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

    else:
        cnt.append(c) def merge(A, left, mid, right, cnt):
    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(1e10)
    R.append(1e10)

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

    else:
        cnt.append(c) merge def mergeSort(A, left, right, cnt):
    if left+1 < right:
        mid = (left+right) // 2
        mergeSort(A, left, mid, cnt)
        mergeSort(A, mid, right, cnt)
        merge(A, left, mid, right, cnt) def mergeSort(A, left, right, cnt):
    if left+1 < right:
        mid = (left+right) // 2
        mergeSort(A, left, mid, cnt)
        mergeSort(A, mid, right, cnt)
        merge(A, left, mid, right, cnt) mergeSort def main():
    cnt = []
    _ = int(input())
    S = list(map(int, input().split()))
    mergeSort(S, 0, len(S), cnt)
    print(*S)
    print(sum(cnt)) def main():
    cnt = []
    _ = int(input())
    S = list(map(int, input().split()))
    mergeSort(S, 0, len(S), cnt)
    print(*S)
    print(sum(cnt)) main
def merge(A, left, mid, right, cnt):
    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(1e10)
    R.append(1e10)

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

    else:
        cnt.append(c)


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


def main():
    cnt = []
    _ = int(input())
    S = list(map(int, input().split()))
    mergeSort(S, 0, len(S), cnt)
    print(*S)
    print(sum(cnt))


if __name__ == "__main__":
    main()

