from __future__ import annotations




def       _snake_case	(   lowerCAmelCase							:   list[list[int]]	):
		"""simple docstring"""







		SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    len(lowerCAmelCase	)
		# We need to create solution object to save path.
		SCREAMING_SNAKE_CASE_  :		str				      =    [[0 for _ in range(lowerCAmelCase	)] for _ in range(lowerCAmelCase	)]
		SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    run_maze(lowerCAmelCase   , 0   , 0   , lowerCAmelCase	)
		if solved:
				print("\n".join(str(lowerCAmelCase	) for row in solutions	)	)
		else:
				print("No solution exists!"	)
		return solved




def       _snake_case	(   lowerCAmelCase							:   list[list[int]]   , lowerCAmelCase							:   int   , lowerCAmelCase							:   int   , lowerCAmelCase							:   list[list[int]]	):
		"""simple docstring"""







		SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    len(lowerCAmelCase	)
		# Final check point.
		if i == j == (size - 1):
				SCREAMING_SNAKE_CASE_  :		List[str]				      =    1
				return True

		SCREAMING_SNAKE_CASE_  :		List[Any]				      =    (not i < 0) and (not j < 0)  # Check lower bounds
		SCREAMING_SNAKE_CASE_  :		List[str]				      =    (i < size) and (j < size)  # Check upper bounds

		if lower_flag and upper_flag:
				# check for already visited and block points.
				SCREAMING_SNAKE_CASE_  :		int				      =    (not solutions[i][j]) and (not maze[i][j])
				if block_flag:
						# check visited
						SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    1

						# check for directions
						if (
						    run_maze(lowerCAmelCase   , i + 1   , lowerCAmelCase   , lowerCAmelCase	)
						    or run_maze(lowerCAmelCase   , lowerCAmelCase   , j + 1   , lowerCAmelCase	)
						    or run_maze(lowerCAmelCase   , i - 1   , lowerCAmelCase   , lowerCAmelCase	)
						    or run_maze(lowerCAmelCase   , lowerCAmelCase   , j - 1   , lowerCAmelCase	)
						):
								return True

						SCREAMING_SNAKE_CASE_  :		List[str]				      =    0
						return False
		return False


if __name__ == "__main__":
		import doctest

		doctest.testmod()

from functools import lru_cache




@lru_cache
def       _snake_case	(   lowerCAmelCase							:   int	):
		"""simple docstring"""







		if num < 0:
				raise ValueError("Number should not be negative."	)

		return 1 if num in (0, 1) else num * factorial(num - 1	)


if __name__ == "__main__":
		import doctest

		doctest.testmod()
