def main():
    cnt = 0

    def merge(A, l, mid, r):
        nonlocal cnt
        n1 = mid - l
        n2 = r - mid
        L = [A[l + i] for i in range(n1)]
        R = [A[mid + i] for i in range(n2)]
        L.append(1 << 60)
        R.append(1 << 60)
        i = 0
        j = 0
        for k in range(l, r):
            if L[i] <= R[j]:
                cnt += 1
                A[k] = L[i]
                i = i + 1
            else:
                cnt += 1
                A[k] = R[j]
                j = j + 1

    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)

    N = int(input())
    S = [int(i) for i in input().split()]
    merge_sort(S, 0, N)
    print(*S)
    print(cnt)


if __name__ == '__main__':
    main()
 def main():
    cnt = 0

    def merge(A, l, mid, r):
        nonlocal cnt
        n1 = mid - l
        n2 = r - mid
        L = [A[l + i] for i in range(n1)]
        R = [A[mid + i] for i in range(n2)]
        L.append(1 << 60)
        R.append(1 << 60)
        i = 0
        j = 0
        for k in range(l, r):
            if L[i] <= R[j]:
                cnt += 1
                A[k] = L[i]
                i = i + 1
            else:
                cnt += 1
                A[k] = R[j]
                j = j + 1

    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)

    N = int(input())
    S = [int(i) for i in input().split()]
    merge_sort(S, 0, N)
    print(*S)
    print(cnt) main cnt = 0 cnt 0 def merge(A, l, mid, r):
        nonlocal cnt
        n1 = mid - l
        n2 = r - mid
        L = [A[l + i] for i in range(n1)]
        R = [A[mid + i] for i in range(n2)]
        L.append(1 << 60)
        R.append(1 << 60)
        i = 0
        j = 0
        for k in range(l, r):
            if L[i] <= R[j]:
                cnt += 1
                A[k] = L[i]
                i = i + 1
            else:
                cnt += 1
                A[k] = R[j]
                j = j + 1

     merge nonlocal cnt n1 = mid - l n1 mid - l mid l n2 = r - mid n2 r - mid r mid A[l + i] for i in range(n1) for i in range(n1) i range(n1) range n1 for i in range(n1) A[l + i] A l + i l i L = [A[l + i] for i in range(n1)] L [A[l + 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(1 << 60) L.append L append 1 << 60 1 60 R.append(1 << 60) R.append R append 1 << 60 1 60 i = 0 i 0 j = 0 j 0 for k in range(l, r):
            if L[i] <= R[j]:
                cnt += 1
                A[k] = L[i]
                i = i + 1
            else:
                cnt += 1
                A[k] = R[j]
                j = j + 1

     k range(l, r) range l r if L[i] <= R[j]:
                cnt += 1
                A[k] = L[i]
                i = i + 1
            else:
                cnt += 1
                A[k] = R[j]
                j = j + 1

     L[i] <= R[j] L[i] L i R[j] R j cnt += 1 cnt 1 A[k] = L[i] A[k] A k L[i] L i i = i + 1 i i + 1 i 1 cnt += 1 cnt 1 A[k] = R[j] A[k] A k R[j] R j j = j + 1 j j + 1 j 1 A A l l mid mid r r 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)

     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 A A left left right right N = int(input()) N int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i S = [int(i) for i in input().split()] S [int(i) for i in input().split()] merge_sort(S, 0, N) merge_sort S 0 N print(*S) print *S S print(cnt) print cnt if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    cnt = 0

    def merge(A, l, mid, r):
        nonlocal cnt
        n1 = mid - l
        n2 = r - mid
        L = [A[l + i] for i in range(n1)]
        R = [A[mid + i] for i in range(n2)]
        L.append(1 << 60)
        R.append(1 << 60)
        i = 0
        j = 0
        for k in range(l, r):
            if L[i] <= R[j]:
                cnt += 1
                A[k] = L[i]
                i = i + 1
            else:
                cnt += 1
                A[k] = R[j]
                j = j + 1

    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)

    N = int(input())
    S = [int(i) for i in input().split()]
    merge_sort(S, 0, N)
    print(*S)
    print(cnt) def main():
    cnt = 0

    def merge(A, l, mid, r):
        nonlocal cnt
        n1 = mid - l
        n2 = r - mid
        L = [A[l + i] for i in range(n1)]
        R = [A[mid + i] for i in range(n2)]
        L.append(1 << 60)
        R.append(1 << 60)
        i = 0
        j = 0
        for k in range(l, r):
            if L[i] <= R[j]:
                cnt += 1
                A[k] = L[i]
                i = i + 1
            else:
                cnt += 1
                A[k] = R[j]
                j = j + 1

    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)

    N = int(input())
    S = [int(i) for i in input().split()]
    merge_sort(S, 0, N)
    print(*S)
    print(cnt) main
def main():
    cnt = 0

    def merge(A, l, mid, r):
        nonlocal cnt
        n1 = mid - l
        n2 = r - mid
        L = [A[l + i] for i in range(n1)]
        R = [A[mid + i] for i in range(n2)]
        L.append(1 << 60)
        R.append(1 << 60)
        i = 0
        j = 0
        for k in range(l, r):
            if L[i] <= R[j]:
                cnt += 1
                A[k] = L[i]
                i = i + 1
            else:
                cnt += 1
                A[k] = R[j]
                j = j + 1

    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)

    N = int(input())
    S = [int(i) for i in input().split()]
    merge_sort(S, 0, N)
    print(*S)
    print(cnt)


if __name__ == '__main__':
    main()

