def binary_search(array):
left, right = 0, len(array)
while left < right:
mid = (left + right) // 2
if condition(array[mid]):
right = mid
else:
left = mid + 1
return left
def binary_search(A):
left, right = 1, len(A) - 1
while left < right:
mid = (left + right) // 2
if A[mid - 1] < A[mid]:
right = mid - 1
elif A[mid] > A[mid + 1]:
left = mid + 1
else:
return mid
return left