


"""simple docstring"""







from heapq import heappop, heappush

import numpy as np




def   UpperCAmelCase__			(lowerCAmelCase_    ,		lowerCAmelCase_    ,		lowerCAmelCase_    ,		lowerCAmelCase_    ,		):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE  ,    __SCREAMING_SNAKE_CASE		  =							grid.shape
					__SCREAMING_SNAKE_CASE		  =							[-1, 1, 0, 0]
					__SCREAMING_SNAKE_CASE		  =							[0, 0, -1, 1]
					if allow_diagonal:
										dx += [-1, -1, 1, 1]
										dy += [-1, 1, -1, 1]

					__SCREAMING_SNAKE_CASE  ,    __SCREAMING_SNAKE_CASE		  =							[(0, source)], set()
					__SCREAMING_SNAKE_CASE		  =							np.full((rows, cols)    ,		np.inf  )
					__SCREAMING_SNAKE_CASE		  =							0
					__SCREAMING_SNAKE_CASE		  =							np.empty((rows, cols)    ,		dtype=_a  )
					__SCREAMING_SNAKE_CASE		  =							None

					while queue:
										((__SCREAMING_SNAKE_CASE)  ,    (__SCREAMING_SNAKE_CASE))		  =							heappop(_a  )
										if (x, y) in visited:
															continue
										visited.add((x, y)  )

										if (x, y) == destination:
															__SCREAMING_SNAKE_CASE		  =							[]
															while (x, y) != source:
																				path.append((x, y)  )
																				__SCREAMING_SNAKE_CASE  ,    __SCREAMING_SNAKE_CASE		  =							predecessors[x, y]
															path.append(_a  )  # add the source manually
															path.reverse()
															return matrix[destination], path

										for i in range(len(_a  )  ):
															__SCREAMING_SNAKE_CASE  ,    __SCREAMING_SNAKE_CASE		  =							x + dx[i], y + dy[i]
															if 0 <= nx < rows and 0 <= ny < cols:
																				__SCREAMING_SNAKE_CASE		  =							grid[nx][ny]
																				if next_node == 1 and matrix[nx, ny] > dist + 1:
																									heappush(_a    ,		(dist + 1, (nx, ny))  )
																									__SCREAMING_SNAKE_CASE		  =							dist + 1
																									__SCREAMING_SNAKE_CASE		  =							(x, y)

					return np.inf, []


if __name__ == "__main__":
		import doctest

		doctest.testmod()



"""simple docstring"""


def   _A					(	_a	:						Optional[int]     ,   _a	:						str				):



      """simple docstring"""






      A				  =		0
      A				  =		len(_a				) - 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

            A				  =		left + ((item - sorted_collection[left]) * (right - left)) // (
                sorted_collection[right] - sorted_collection[left]
            )

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

            A				  =		sorted_collection[point]
            if current_item == item:
                  return point
            else:
                  if point < left:
                        A				  =		left
                        A				  =		point
                  elif point > right:
                        A				  =		right
                        A				  =		point
                  else:
                        if item < current_item:
                              A				  =		point - 1
                        else:
                              A				  =		point + 1
      return None



def   _A					(	_a	:						Any     ,   _a	:						List[str]     ,   _a	:						Dict     ,   _a	:						List[str]				):



      """simple docstring"""






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

      A				  =		left + ((item - sorted_collection[left]) * (right - left)) // (
          sorted_collection[right] - sorted_collection[left]
      )

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

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



def   _A					(	_a	:						List[Any]				):



      """simple docstring"""






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


if __name__ == "__main__":
  import sys
  UpperCAmelCase													=0
  if debug == 1:
    UpperCAmelCase													=[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")
    UpperCAmelCase													=67

  UpperCAmelCase													=interpolation_search(collection, target)
  if result is not None:
    print(f"""{target} found at positions: {result}""")
  else:
    print("Not found")




