if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    MAX = 500000
    SENTINEL = 2000000000

    L = [None]*(MAX//2+2)
    R = [None]*(MAX//2+2)
    cnt = 0

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

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

    n = int(input())

    A = list(map(int, input().split()))

    cnt = mergeSort(A, n, 0, n, cnt)

    print(' '.join(map(str, A)))
    print(cnt)
 if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    MAX = 500000
    SENTINEL = 2000000000

    L = [None]*(MAX//2+2)
    R = [None]*(MAX//2+2)
    cnt = 0

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

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

    n = int(input())

    A = list(map(int, input().split()))

    cnt = mergeSort(A, n, 0, n, cnt)

    print(' '.join(map(str, A)))
    print(cnt) __name__ == '__main__' __name__ '__main__' import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline MAX = 500000 MAX 500000 SENTINEL = 2000000000 SENTINEL 2000000000 L = [None]*(MAX//2+2) L [None]*(MAX//2+2) [None] None MAX//2+2 MAX//2 MAX 2 2 R = [None]*(MAX//2+2) R [None]*(MAX//2+2) [None] None MAX//2+2 MAX//2 MAX 2 2 cnt = 0 cnt 0 def merge(A, n ,left, mid, right, cnt):
        n1 = mid - left
        n2 = right - mid
        for i in range(n1):
            L[i] = A[left + i]
        for i in range(n2):
            R[i] = A[mid + i]
        L[n1] = R[n2] = SENTINEL
        i, j = 0, 0
        for k in range(left, right):
            cnt += 1
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                j += 1
        return cnt

     merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid for i in range(n1):
            L[i] = A[left + i]
         i range(n1) range n1 L[i] = A[left + i] L[i] L i A[left + i] A left + i left i for i in range(n2):
            R[i] = A[mid + i]
         i range(n2) range n2 R[i] = A[mid + i] R[i] R i A[mid + i] A mid + i mid i L[n1] = R[n2] = SENTINEL L[n1] L n1 SENTINEL = R[n2] = SENTINEL R[n2] R n2 SENTINEL i, j = 0, 0 i 0 j 0 for k in range(left, right):
            cnt += 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 cnt += 1 cnt 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 cnt cnt A A n n left left mid mid right right cnt cnt def mergeSort(A, n, left, right, cnt):
        if left+1 < right:
            mid = (left + right)//2
            cnt = mergeSort(A, n, left, mid, cnt)
            cnt = mergeSort(A, n, mid, right, cnt)
            cnt = merge(A, n, left, mid, right, cnt)
        return cnt

     mergeSort if left+1 < right:
            mid = (left + right)//2
            cnt = mergeSort(A, n, left, mid, cnt)
            cnt = mergeSort(A, n, mid, right, cnt)
            cnt = merge(A, n, 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 cnt = mergeSort(A, n, left, mid, cnt) cnt mergeSort(A, n, left, mid, cnt) mergeSort A n left mid cnt cnt = mergeSort(A, n, mid, right, cnt) cnt mergeSort(A, n, mid, right, cnt) mergeSort A n mid right cnt cnt = merge(A, n, left, mid, right, cnt) cnt merge(A, n, left, mid, right, cnt) merge A n left mid right cnt return cnt cnt A A n n left left right right cnt cnt 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 cnt = mergeSort(A, n, 0, n, cnt) cnt mergeSort(A, n, 0, n, cnt) mergeSort A n 0 n cnt print(' '.join(map(str, A))) print ' '.join(map(str, A)) ' '.join ' ' join map(str, A) map str A print(cnt) print cnt cnt = mergeSort(A, n, 0, n, cnt) mergeSort(A, n, 0, n, cnt) cnt R = [None]*(MAX//2+2) [None]*(MAX//2+2) R L = [None]*(MAX//2+2) [None]*(MAX//2+2) L input = sys.stdin.readline sys.stdin.readline input def mergeSort(A, n, left, right, cnt):
        if left+1 < right:
            mid = (left + right)//2
            cnt = mergeSort(A, n, left, mid, cnt)
            cnt = mergeSort(A, n, mid, right, cnt)
            cnt = merge(A, n, left, mid, right, cnt)
        return cnt

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

     mergeSort n = int(input()) int(input()) n cnt = 0 0 cnt def merge(A, n ,left, mid, right, cnt):
        n1 = mid - left
        n2 = right - mid
        for i in range(n1):
            L[i] = A[left + i]
        for i in range(n2):
            R[i] = A[mid + i]
        L[n1] = R[n2] = SENTINEL
        i, j = 0, 0
        for k in range(left, right):
            cnt += 1
            if L[i] <= R[j]:
                A[k] = L[i]
                i += 1
            else:
                A[k] = R[j]
                j += 1
        return cnt

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

     merge MAX = 500000 500000 MAX SENTINEL = 2000000000 2000000000 SENTINEL A = list(map(int, input().split())) list(map(int, input().split())) A
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    MAX = 500000
    SENTINEL = 2000000000

    L = [None]*(MAX//2+2)
    R = [None]*(MAX//2+2)
    cnt = 0

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

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

    n = int(input())

    A = list(map(int, input().split()))

    cnt = mergeSort(A, n, 0, n, cnt)

    print(' '.join(map(str, A)))
    print(cnt)

