import sys, math
input = sys.stdin.readline

MAX = 2e9

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]
    L.append(MAX)
    R = A[mid:right]
    R.append(MAX)
    merged = []
    index_L = 0
    index_R = 0
    comp_cnt = 0
    for _ in range(n1+n2):
        cand_L = L[index_L]
        cand_R = R[index_R]
        comp_cnt += 1
        if (cand_L < cand_R):
            merged.append(cand_L)
            index_L += 1
        else:
            merged.append(cand_R)
            index_R += 1
    A[left:right] = merged
    return comp_cnt
        
def merge_sort(A, left, right):
    comp_cnt = 0
    if (left + 1 < right):
        # Devide
        mid = (left + right) // 2
        # Solve
        _, cnt = merge_sort(A, left, mid)
        comp_cnt += cnt
        _, cnt = merge_sort(A, mid, right)
        comp_cnt += cnt
        # Conquer
        comp_cnt += merge(A, left, mid, right)
    return A, comp_cnt

def main():
    N = int(input())
    S = list(map(int, input().split()))
    left = 0
    right = len(S)
    merged, cnt = merge_sort(S, left, right)
    print(" ".join([str(x) for x in merged]))
    print(cnt)

if __name__ == "__main__":
    main() import sys, math sys math input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline MAX = 2e9 MAX 2e9 def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]
    L.append(MAX)
    R = A[mid:right]
    R.append(MAX)
    merged = []
    index_L = 0
    index_R = 0
    comp_cnt = 0
    for _ in range(n1+n2):
        cand_L = L[index_L]
        cand_R = R[index_R]
        comp_cnt += 1
        if (cand_L < cand_R):
            merged.append(cand_L)
            index_L += 1
        else:
            merged.append(cand_R)
            index_R += 1
    A[left:right] = merged
    return comp_cnt
         merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = A[left:mid] L A[left:mid] A left:mid left mid L.append(MAX) L.append L append MAX R = A[mid:right] R A[mid:right] A mid:right mid right R.append(MAX) R.append R append MAX merged = [] merged [] index_L = 0 index_L 0 index_R = 0 index_R 0 comp_cnt = 0 comp_cnt 0 for _ in range(n1+n2):
        cand_L = L[index_L]
        cand_R = R[index_R]
        comp_cnt += 1
        if (cand_L < cand_R):
            merged.append(cand_L)
            index_L += 1
        else:
            merged.append(cand_R)
            index_R += 1
     _ range(n1+n2) range n1+n2 n1 n2 cand_L = L[index_L] cand_L L[index_L] L index_L cand_R = R[index_R] cand_R R[index_R] R index_R comp_cnt += 1 comp_cnt 1 if (cand_L < cand_R):
            merged.append(cand_L)
            index_L += 1
        else:
            merged.append(cand_R)
            index_R += 1
     cand_L < cand_R cand_L cand_R merged.append(cand_L) merged.append merged append cand_L index_L += 1 index_L 1 merged.append(cand_R) merged.append merged append cand_R index_R += 1 index_R 1 A[left:right] = merged A[left:right] A left:right left right merged return comp_cnt comp_cnt A A left left mid mid right right def merge_sort(A, left, right):
    comp_cnt = 0
    if (left + 1 < right):
        # Devide
        mid = (left + right) // 2
        # Solve
        _, cnt = merge_sort(A, left, mid)
        comp_cnt += cnt
        _, cnt = merge_sort(A, mid, right)
        comp_cnt += cnt
        # Conquer
        comp_cnt += merge(A, left, mid, right)
    return A, comp_cnt merge_sort comp_cnt = 0 comp_cnt 0 if (left + 1 < right):
        # Devide
        mid = (left + right) // 2
        # Solve
        _, cnt = merge_sort(A, left, mid)
        comp_cnt += cnt
        _, cnt = merge_sort(A, mid, right)
        comp_cnt += cnt
        # Conquer
        comp_cnt += 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 _, cnt = merge_sort(A, left, mid) _ merge_sort(A, left, mid) merge_sort A left mid cnt comp_cnt += cnt comp_cnt cnt _, cnt = merge_sort(A, mid, right) _ merge_sort(A, mid, right) merge_sort A mid right cnt comp_cnt += cnt comp_cnt cnt comp_cnt += merge(A, left, mid, right) comp_cnt merge(A, left, mid, right) merge A left mid right return A, comp_cnt return A, comp_cnt A comp_cnt A A left left right right def main():
    N = int(input())
    S = list(map(int, input().split()))
    left = 0
    right = len(S)
    merged, cnt = merge_sort(S, left, right)
    print(" ".join([str(x) for x in merged]))
    print(cnt) main N = int(input()) N 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 left = 0 left 0 right = len(S) right len(S) len S merged, cnt = merge_sort(S, left, right) merged merge_sort(S, left, right) merge_sort S left right cnt str(x) for x in merged for x in merged x merged for x in merged str(x) str x print(" ".join([str(x) for x in merged])) print " ".join([str(x) for x in merged]) " ".join " " join [str(x) for x in merged] print(cnt) print cnt if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main input = sys.stdin.readline sys.stdin.readline input def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]
    L.append(MAX)
    R = A[mid:right]
    R.append(MAX)
    merged = []
    index_L = 0
    index_R = 0
    comp_cnt = 0
    for _ in range(n1+n2):
        cand_L = L[index_L]
        cand_R = R[index_R]
        comp_cnt += 1
        if (cand_L < cand_R):
            merged.append(cand_L)
            index_L += 1
        else:
            merged.append(cand_R)
            index_R += 1
    A[left:right] = merged
    return comp_cnt
         def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]
    L.append(MAX)
    R = A[mid:right]
    R.append(MAX)
    merged = []
    index_L = 0
    index_R = 0
    comp_cnt = 0
    for _ in range(n1+n2):
        cand_L = L[index_L]
        cand_R = R[index_R]
        comp_cnt += 1
        if (cand_L < cand_R):
            merged.append(cand_L)
            index_L += 1
        else:
            merged.append(cand_R)
            index_R += 1
    A[left:right] = merged
    return comp_cnt
         merge def main():
    N = int(input())
    S = list(map(int, input().split()))
    left = 0
    right = len(S)
    merged, cnt = merge_sort(S, left, right)
    print(" ".join([str(x) for x in merged]))
    print(cnt) def main():
    N = int(input())
    S = list(map(int, input().split()))
    left = 0
    right = len(S)
    merged, cnt = merge_sort(S, left, right)
    print(" ".join([str(x) for x in merged]))
    print(cnt) main MAX = 2e9 2e9 MAX def merge_sort(A, left, right):
    comp_cnt = 0
    if (left + 1 < right):
        # Devide
        mid = (left + right) // 2
        # Solve
        _, cnt = merge_sort(A, left, mid)
        comp_cnt += cnt
        _, cnt = merge_sort(A, mid, right)
        comp_cnt += cnt
        # Conquer
        comp_cnt += merge(A, left, mid, right)
    return A, comp_cnt def merge_sort(A, left, right):
    comp_cnt = 0
    if (left + 1 < right):
        # Devide
        mid = (left + right) // 2
        # Solve
        _, cnt = merge_sort(A, left, mid)
        comp_cnt += cnt
        _, cnt = merge_sort(A, mid, right)
        comp_cnt += cnt
        # Conquer
        comp_cnt += merge(A, left, mid, right)
    return A, comp_cnt merge_sort
import sys, math
input = sys.stdin.readline

MAX = 2e9

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]
    L.append(MAX)
    R = A[mid:right]
    R.append(MAX)
    merged = []
    index_L = 0
    index_R = 0
    comp_cnt = 0
    for _ in range(n1+n2):
        cand_L = L[index_L]
        cand_R = R[index_R]
        comp_cnt += 1
        if (cand_L < cand_R):
            merged.append(cand_L)
            index_L += 1
        else:
            merged.append(cand_R)
            index_R += 1
    A[left:right] = merged
    return comp_cnt
        
def merge_sort(A, left, right):
    comp_cnt = 0
    if (left + 1 < right):
        # Devide
        mid = (left + right) // 2
        # Solve
        _, cnt = merge_sort(A, left, mid)
        comp_cnt += cnt
        _, cnt = merge_sort(A, mid, right)
        comp_cnt += cnt
        # Conquer
        comp_cnt += merge(A, left, mid, right)
    return A, comp_cnt

def main():
    N = int(input())
    S = list(map(int, input().split()))
    left = 0
    right = len(S)
    merged, cnt = merge_sort(S, left, right)
    print(" ".join([str(x) for x in merged]))
    print(cnt)

if __name__ == "__main__":
    main()
