




"""simple docstring"""







from heapq import heappop, heappush

import numpy as np





def 				lowercase       (snake_case__ :			np.ndarray   ,							snake_case__ :			tuple[int, int]   ,							snake_case__ :			tuple[int, int]   ,							snake_case__ :			bool   ,							)  ->	Optional[int]:


				'''simple docstring'''






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

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

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

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

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

				return np.inf, []


if __name__ == "__main__":
		import doctest

		doctest.testmod()









'''simple docstring'''
from math import factorial

UpperCAmelCase_			:  List[str]										=   {str(d): factorial(d) for d in range(1_0)}


def       _lowercase							(					UpperCamelCase__							:       int      ):
 return sum(DIGIT_FACTORIAL[d] for d in str(UpperCamelCase__      )      )


def       _lowercase							(					):
 __A	:		Union[str, Any]	  =      7 * factorial(9      ) + 1
 return sum(i for i in range(3,					UpperCamelCase__      ) if sum_of_digit_factorial(UpperCamelCase__      ) == i      )


if __name__ == "__main__":
 print(f'''{solution() = }''')






