



"""simple docstring"""

def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Any				,    SCREAMING_SNAKE_CASE__ :  List[str]			):
					snake_case_					:		Optional[Any] 					=					0
					snake_case_					:		int 					=					len(SCREAMING_SNAKE_CASE__			) - 1

					while left <= right:
										# avoid divided by 0 during interpolation
										if sorted_collection[left] == sorted_collection[right]:
															if sorted_collection[left] == item:
																				return left
															else:
																				return None

										snake_case_					:		Optional[int] 					=					left + ((item - sorted_collection[left]) * (right - left)) // (
										    sorted_collection[right] - sorted_collection[left]
										)

										# out of range check
										if point < 0 or point >= len(SCREAMING_SNAKE_CASE__			):
															return None

										snake_case_					:		Dict 					=					sorted_collection[point]
										if current_item == item:
															return point
										else:
															if point < left:
																				snake_case_					:		List[Any] 					=					left
																				snake_case_					:		List[Any] 					=					point
															elif point > right:
																				snake_case_					:		List[Any] 					=					right
																				snake_case_					:		Tuple 					=					point
															else:
																				if item < current_item:
																									snake_case_					:		List[Any] 					=					point - 1
																				else:
																									snake_case_					:		Union[str, Any] 					=					point + 1
					return None







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  str				,    SCREAMING_SNAKE_CASE__ :  Tuple				,    SCREAMING_SNAKE_CASE__ :  int				,    SCREAMING_SNAKE_CASE__ :  Optional[Any]			):





					if sorted_collection[left] == sorted_collection[right]:
										if sorted_collection[left] == item:
															return left
										else:
															return None

					snake_case_					:		int 					=					left + ((item - sorted_collection[left]) * (right - left)) // (
					    sorted_collection[right] - sorted_collection[left]
					)

					# out of range check
					if point < 0 or point >= len(SCREAMING_SNAKE_CASE__			):
										return None

					if sorted_collection[point] == item:
										return point
					elif point < left:
										return interpolation_search_by_recursion(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			)
					elif point > right:
										return interpolation_search_by_recursion(SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__			)
					else:
										if sorted_collection[point] > item:
															return interpolation_search_by_recursion(
															    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    point - 1			)
										else:
															return interpolation_search_by_recursion(
															    SCREAMING_SNAKE_CASE__				,    SCREAMING_SNAKE_CASE__				,    point + 1				,    SCREAMING_SNAKE_CASE__			)







def 							SCREAMING_SNAKE_CASE__      (		SCREAMING_SNAKE_CASE__ :  Any			):





					if collection != sorted(SCREAMING_SNAKE_CASE__			):
										raise ValueError("""Collection must be ascending sorted"""			)
					return True


if __name__ == "__main__":
			import sys
			a_			   =					0
			if debug == 1:
						a_			   =					[10, 30, 40, 45, 50, 66, 77, 93]
						try:
									__assert_sorted(collection)
						except ValueError:
									sys.exit('''Sequence must be ascending sorted to apply interpolation search''')
						a_			   =					67

			a_			   =					interpolation_search(collection, target)
			if result is not None:
						print(F'''{target} found at positions: {result}''')
			else:
						print('''Not found''')









"""simple docstring"""

from copy import deepcopy







class    __lowercase     :







						"""simple docstring"""







						def __init__(self   ,		lowercase__ = None   ,		lowercase__ = None       ):

											if arr is None and size is not None:
																snake_case_					:		str 					=					size
																snake_case_					:		Optional[Any] 					=					[0] * size
											elif arr is not None:
																self.init(lowercase__       )
											else:
																raise ValueError("""Either arr or size must be specified"""       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											snake_case_					:		Optional[Any] 					=					len(lowercase__       )
											snake_case_					:		int 					=					deepcopy(lowercase__       )
											for i in range(1   ,		self.size       ):
																snake_case_					:		Optional[Any] 					=					self.next_(lowercase__       )
																if j < self.size:
																					self.tree[j] += self.tree[i]







						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Dict 					=					self.tree[:]
											for i in range(self.size - 1   ,		0   ,		-1       ):
																snake_case_					:		Optional[int] 					=					self.next_(lowercase__       )
																if j < self.size:
																					arr[j] -= arr[i]
											return arr







						@staticmethod
						def 						__UpperCamelCase							(lowercase__       ):
											return index + (index & (-index))







						@staticmethod
						def 						__UpperCamelCase							(lowercase__       ):
											return index - (index & (-index))







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__       ):
											if index == 0:
																self.tree[0] += value
																return
											while index < self.size:
																self.tree[index] += value
																snake_case_					:		Tuple 					=					self.next_(lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__       ):
											self.add(lowercase__   ,		value - self.get(lowercase__       )       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											if right == 0:
																return 0
											snake_case_					:		List[str] 					=					self.tree[0]
											right -= 1  # make right inclusive
											while right > 0:
																result += self.tree[right]
																snake_case_					:		Optional[int] 					=					self.prev(lowercase__       )
											return result







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__       ):
											return self.prefix(lowercase__       ) - self.prefix(lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											return self.query(lowercase__   ,		index + 1       )







						def 						__UpperCamelCase							(self   ,		lowercase__       ):
											value -= self.tree[0]
											if value < 0:
																return -1

											snake_case_					:		Tuple 					=					1  # Largest power of 2 <= size
											while j * 2 < self.size:
																j *= 2

											snake_case_					:		Tuple 					=					0

											while j > 0:
																if i + j < self.size and self.tree[i + j] <= value:
																					value -= self.tree[i + j]
																					i += j
																j //= 2
											return i


if __name__ == "__main__":
			import doctest

			doctest.testmod()




