def max_heapify(arr, end, simulation, iteration):
    last_parent = (end - 1) // 2
    for parent in range(last_parent, -1, -1):
        current_parent = parent
        while current_parent <= last_parent:
            child = 2 * current_parent + 1
            if child + 1 <= end and arr[child] < arr[child + 1]:
                child = child + 1
            if arr[child] > arr[current_parent]:
                arr[current_parent], arr[child] = arr[child], arr[current_parent]
                current_parent = child
                if simulation:
                    iteration = iteration + 1
                    print("iteration",iteration,":",*arr)
            else:
                break
    arr[0], arr[end] = arr[end], arr[0]
    return iteration