INF = int(1e18)

def merge(A, left, mid, right):
    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
    count = 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
        c1 = merge_sort(A, left, mid)
        c2 = merge_sort(A, mid, right)
        c = merge(A, left, mid, right)
        return c + c1 + c2
    else:
        return 0

if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().split()))
    c = merge_sort(A, 0, n)

    print(" ".join(map(str, A)))
    print(c) INF = int(1e18) INF int(1e18) int 1e18 def merge(A, left, mid, right):
    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
    count = 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 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 count = 0 count 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
        c1 = merge_sort(A, left, mid)
        c2 = merge_sort(A, mid, right)
        c = merge(A, left, mid, right)
        return c + c1 + c2
    else:
        return 0 merge_sort if left + 1 < right:
        mid = (left + right) // 2
        c1 = merge_sort(A, left, mid)
        c2 = merge_sort(A, mid, right)
        c = merge(A, left, mid, right)
        return c + c1 + c2
    else:
        return 0 left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 c1 = merge_sort(A, left, mid) c1 merge_sort(A, left, mid) merge_sort A left mid c2 = merge_sort(A, mid, right) c2 merge_sort(A, mid, right) merge_sort A mid right c = merge(A, left, mid, right) c merge(A, left, mid, right) merge A left mid right return c + c1 + c2 c + c1 + c2 c + c1 c c1 c2 return 0 0 A A left left right right if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().split()))
    c = merge_sort(A, 0, n)

    print(" ".join(map(str, A)))
    print(c) __name__ == '__main__' __name__ '__main__' 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 c = merge_sort(A, 0, n) c merge_sort(A, 0, n) merge_sort A 0 n print(" ".join(map(str, A))) print " ".join(map(str, A)) " ".join " " join map(str, A) map str A print(c) print c INF = int(1e18) int(1e18) INF n = int(input()) int(input()) n A = list(map(int, input().split())) list(map(int, input().split())) A def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        c1 = merge_sort(A, left, mid)
        c2 = merge_sort(A, mid, right)
        c = merge(A, left, mid, right)
        return c + c1 + c2
    else:
        return 0 def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        c1 = merge_sort(A, left, mid)
        c2 = merge_sort(A, mid, right)
        c = merge(A, left, mid, right)
        return c + c1 + c2
    else:
        return 0 merge_sort def merge(A, left, mid, right):
    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
    count = 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):
    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
    count = 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 c = merge_sort(A, 0, n) merge_sort(A, 0, n) c
INF = int(1e18)

def merge(A, left, mid, right):
    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
    count = 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
        c1 = merge_sort(A, left, mid)
        c2 = merge_sort(A, mid, right)
        c = merge(A, left, mid, right)
        return c + c1 + c2
    else:
        return 0

if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().split()))
    c = merge_sort(A, 0, n)

    print(" ".join(map(str, A)))
    print(c)
