def upper_bound(arr, value, first, last):
    """Find the upper bound of the value in the array

    upper bound: the first element in arr that is larger than value

    Args:
        arr         : input array
        value       : target value
        first       : starting point of the search, inclusive
        last        : ending point of the search, exclusive

    Return
        index       : integer
                        if index == last => upper bound does not exist
                        else => arr[index] > value
    """

    while first < last:

        mid = first + (last - first) // 2

        if arr[mid] <= value:
            first = mid + 1
        else:
            last = mid

    return first