import math


def binary_search(t, x, start, end):
    """Find the index i of t with t[i] <= x <= t[i+1].
    Under the assumption that t is nondecreasing t[j] <= t[j+1]."""
    mid = math.floor((start + end) / 2)
    if ((start - end) == 0) or ((t[mid] <= x) and (x < t[mid+1])):
        return mid
    elif t[mid] <= x:
        return binary_search(t, x, mid + 1, end)
    else:
        return binary_search(t, x, start, mid - 1)