


"""simple docstring"""






from heapq import heappop, heappush

import numpy as np


def __lowercase     (      lowerCamelCase_  :      np.ndarray						,					lowerCamelCase_  :      tuple[int, int]						,					lowerCamelCase_  :      tuple[int, int]						,					lowerCamelCase_  :      bool						,					):
				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=lowerCamelCase_  )
				SCREAMING_SNAKE_CASE__     							=				None

				while queue:
								((SCREAMING_SNAKE_CASE__)							,      (SCREAMING_SNAKE_CASE__))     							=				heappop(lowerCamelCase_  )
								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(lowerCamelCase_  )  # add the source manually
												path.reverse()
												return matrix[destination], path

								for i in range(len(lowerCamelCase_  )  ):
												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(lowerCamelCase_						,					(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"""






from maths.is_square_free import is_square_free
from maths.prime_factors import prime_factors


def __lowercase     (      lowerCamelCase_  :      int  ):
				SCREAMING_SNAKE_CASE__     							=				prime_factors(lowerCamelCase_  )
				if is_square_free(lowerCamelCase_  ):
								return -1 if len(lowerCamelCase_  ) % 2 else 1
				return 0


if __name__ == "__main__":
	import doctest

	doctest.testmod()
