def get_interval(T, i, n):
    """ 
        Returns a 3-tuple (T[i], T[i+n], bounds_exceeded) where -inf < n < inf 
        and bounds_exceeded is -1 or +1 if exceeded left or right respectively.
    """
    bounds_exceeded = 0
    last_T_idx = len(T)-1

    if i+n > last_T_idx:
        bounds_exceeded = 1
    elif  i+n < 0:
        bounds_exceeded = -1

    if n >= 0:
        return (T[i], T[min(i+n,last_T_idx)], bounds_exceeded)
    else:
        return (T[max(0,i+n)], T[i], bounds_exceeded)