def bisect_func_right(x, lo, hi, func):
    """Bisect `func(i)`, returning an index such that consecutive values are
    greater than `x`. If `x` is present, the returned index is past its last
    occurrence. EOF is assumed if `func` returns None."""
    while lo < hi:
        mid = (lo + hi) // 2
        k = func(mid)
        if k is not None and x < k:
            hi = mid
        else:
            lo = mid + 1

    return lo