count = 0

def merge_sort(n, nums):
    if n == 1:
        return nums
    left_n = n // 2  # 左側が小さい
    left_sorted = merge_sort(left_n, nums[:left_n]) + [10**9 + 1]  # 番兵
    right_n = n - left_n
    right_sorted = merge_sort(right_n, nums[left_n:]) + [10**9 + 1]  # 番兵
    left_idx = 0
    right_idx = 0
    idx = 0
    sorted_list = [0] * n
    while idx < n:
        if left_sorted[left_idx] < right_sorted[right_idx]:
            sorted_list[idx] = left_sorted[left_idx]
            left_idx += 1
        else:
            sorted_list[idx] = right_sorted[right_idx]
            right_idx += 1
        idx += 1
    global count
    count += idx
    return sorted_list


def main():
    n = int(input())
    nums = list(map(int, input().split(" ")))
    sorted_list = merge_sort(n, nums)
    print(" ".join(map(str, sorted_list)))
    print(count)


if __name__ == "__main__":
    main()
 count = 0 count 0 def merge_sort(n, nums):
    if n == 1:
        return nums
    left_n = n // 2  # 左側が小さい
    left_sorted = merge_sort(left_n, nums[:left_n]) + [10**9 + 1]  # 番兵
    right_n = n - left_n
    right_sorted = merge_sort(right_n, nums[left_n:]) + [10**9 + 1]  # 番兵
    left_idx = 0
    right_idx = 0
    idx = 0
    sorted_list = [0] * n
    while idx < n:
        if left_sorted[left_idx] < right_sorted[right_idx]:
            sorted_list[idx] = left_sorted[left_idx]
            left_idx += 1
        else:
            sorted_list[idx] = right_sorted[right_idx]
            right_idx += 1
        idx += 1
    global count
    count += idx
    return sorted_list merge_sort if n == 1:
        return nums
     n == 1 n 1 return nums nums left_n = n // 2 left_n n // 2 n 2 left_sorted = merge_sort(left_n, nums[:left_n]) + [10**9 + 1] left_sorted merge_sort(left_n, nums[:left_n]) + [10**9 + 1] merge_sort(left_n, nums[:left_n]) merge_sort left_n nums[:left_n] nums :left_n left_n [10**9 + 1] 10**9 + 1 10**9 10 9 1 right_n = n - left_n right_n n - left_n n left_n right_sorted = merge_sort(right_n, nums[left_n:]) + [10**9 + 1] right_sorted merge_sort(right_n, nums[left_n:]) + [10**9 + 1] merge_sort(right_n, nums[left_n:]) merge_sort right_n nums[left_n:] nums left_n: left_n [10**9 + 1] 10**9 + 1 10**9 10 9 1 left_idx = 0 left_idx 0 right_idx = 0 right_idx 0 idx = 0 idx 0 sorted_list = [0] * n sorted_list [0] * n [0] 0 n while idx < n:
        if left_sorted[left_idx] < right_sorted[right_idx]:
            sorted_list[idx] = left_sorted[left_idx]
            left_idx += 1
        else:
            sorted_list[idx] = right_sorted[right_idx]
            right_idx += 1
        idx += 1
     idx < n idx n if left_sorted[left_idx] < right_sorted[right_idx]:
            sorted_list[idx] = left_sorted[left_idx]
            left_idx += 1
        else:
            sorted_list[idx] = right_sorted[right_idx]
            right_idx += 1
         left_sorted[left_idx] < right_sorted[right_idx] left_sorted[left_idx] left_sorted left_idx right_sorted[right_idx] right_sorted right_idx sorted_list[idx] = left_sorted[left_idx] sorted_list[idx] sorted_list idx left_sorted[left_idx] left_sorted left_idx left_idx += 1 left_idx 1 sorted_list[idx] = right_sorted[right_idx] sorted_list[idx] sorted_list idx right_sorted[right_idx] right_sorted right_idx right_idx += 1 right_idx 1 idx += 1 idx 1 global count count += idx count idx return sorted_list sorted_list n n nums nums def main():
    n = int(input())
    nums = list(map(int, input().split(" ")))
    sorted_list = merge_sort(n, nums)
    print(" ".join(map(str, sorted_list)))
    print(count) main n = int(input()) n int(input()) int input() input nums = list(map(int, input().split(" "))) nums list(map(int, input().split(" "))) list map(int, input().split(" ")) map int input().split(" ") ().split () input split " " sorted_list = merge_sort(n, nums) sorted_list merge_sort(n, nums) merge_sort n nums print(" ".join(map(str, sorted_list))) print " ".join(map(str, sorted_list)) " ".join " " join map(str, sorted_list) map str sorted_list print(count) print count if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def merge_sort(n, nums):
    if n == 1:
        return nums
    left_n = n // 2  # 左側が小さい
    left_sorted = merge_sort(left_n, nums[:left_n]) + [10**9 + 1]  # 番兵
    right_n = n - left_n
    right_sorted = merge_sort(right_n, nums[left_n:]) + [10**9 + 1]  # 番兵
    left_idx = 0
    right_idx = 0
    idx = 0
    sorted_list = [0] * n
    while idx < n:
        if left_sorted[left_idx] < right_sorted[right_idx]:
            sorted_list[idx] = left_sorted[left_idx]
            left_idx += 1
        else:
            sorted_list[idx] = right_sorted[right_idx]
            right_idx += 1
        idx += 1
    global count
    count += idx
    return sorted_list def merge_sort(n, nums):
    if n == 1:
        return nums
    left_n = n // 2  # 左側が小さい
    left_sorted = merge_sort(left_n, nums[:left_n]) + [10**9 + 1]  # 番兵
    right_n = n - left_n
    right_sorted = merge_sort(right_n, nums[left_n:]) + [10**9 + 1]  # 番兵
    left_idx = 0
    right_idx = 0
    idx = 0
    sorted_list = [0] * n
    while idx < n:
        if left_sorted[left_idx] < right_sorted[right_idx]:
            sorted_list[idx] = left_sorted[left_idx]
            left_idx += 1
        else:
            sorted_list[idx] = right_sorted[right_idx]
            right_idx += 1
        idx += 1
    global count
    count += idx
    return sorted_list merge_sort count = 0 0 count def main():
    n = int(input())
    nums = list(map(int, input().split(" ")))
    sorted_list = merge_sort(n, nums)
    print(" ".join(map(str, sorted_list)))
    print(count) def main():
    n = int(input())
    nums = list(map(int, input().split(" ")))
    sorted_list = merge_sort(n, nums)
    print(" ".join(map(str, sorted_list)))
    print(count) main
count = 0

def merge_sort(n, nums):
    if n == 1:
        return nums
    left_n = n // 2  # 左側が小さい
    left_sorted = merge_sort(left_n, nums[:left_n]) + [10**9 + 1]  # 番兵
    right_n = n - left_n
    right_sorted = merge_sort(right_n, nums[left_n:]) + [10**9 + 1]  # 番兵
    left_idx = 0
    right_idx = 0
    idx = 0
    sorted_list = [0] * n
    while idx < n:
        if left_sorted[left_idx] < right_sorted[right_idx]:
            sorted_list[idx] = left_sorted[left_idx]
            left_idx += 1
        else:
            sorted_list[idx] = right_sorted[right_idx]
            right_idx += 1
        idx += 1
    global count
    count += idx
    return sorted_list


def main():
    n = int(input())
    nums = list(map(int, input().split(" ")))
    sorted_list = merge_sort(n, nums)
    print(" ".join(map(str, sorted_list)))
    print(count)


if __name__ == "__main__":
    main()

