def bisect_right(data, target, lo, hi):
    """
    Given a sorted array, returns the insertion position of target
    If the value is already present, the insertion post is to the right of all of them
    >>> bisect_right([1,1,2,3,4,5], 1, 0, 6)
    2
    >>> bisect_right([1,1,2,3,4,5], 0, 0, 6)
    0
    >>> bisect_right([1,1,2,3,4,5], 6, 0, 6)
    6
    """
    while lo < hi:
        mid = (lo+hi)/2
        if data[mid] > target:
            hi = mid
        else:
            lo = mid+1
    return lo