def binary_search(x, arr, include_equal = False):
	"""
	Returns the index of the smallest element in an array which is larger
	than a specified element. This assumes that the array is sorted in 
	non-decreasing order. If the element is larger than the largest element 
	in the array, then the length of the array is returned instead. 

	Arguments:
		x (:int) - the element to be searched for
		arr (:int list) - the array sorted in non-decreasing order

	Returns:
		the position of the largest element in 'arr' greater than 'x'

	Examples:
		>>> binary_search(2, [0, 2, 3])
		>>> 2

		>>> binary_search(-1, [0, 2, 3])
		>>> 0

		>>> binary_search(99, [0, 2, 3])
		>>> 3
"""
	if x > arr[-1]:
		return len(arr)
	elif x < arr[0]:
		return 0

	l, r = 0, len(arr) - 1
	while l <= r:
		m = (l + r) >> 1
		if arr[m] == x:
			return m + 1 if not include_equal else m
		elif arr[m] < x:
			l = m + 1
		else:
			r = m - 1

	return l