



'''simple docstring'''
import functools
from typing import Any






def  __SCREAMING_SNAKE_CASE				(  _SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE				):

							# Validation
							if not isinstance(_SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE				) or len(_SCREAMING_SNAKE_CASE				) == 0:
														raise ValueError("""the string should be not empty string"""				)

							if not isinstance(_SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE				) or not all(
							    isinstance(_SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE				) and len(_SCREAMING_SNAKE_CASE				) > 0 for item in words				):
														raise ValueError("""the words should be a list of non-empty strings"""				)

							# Build trie
							_snake_case       =  {}
							_snake_case       =  """WORD_KEEPER"""

							for word in words:
														_snake_case       =  trie
														for c in word:
																					if c not in trie_node:
																												_snake_case       =  {}

																					_snake_case       =  trie_node[c]

														_snake_case       =  True

							_snake_case       =  len(_SCREAMING_SNAKE_CASE				)

							# Dynamic programming method
							@functools.cache
							def is_breakable(_SCREAMING_SNAKE_CASE				) -> bool:
														if index == len_string:
																					return True

														_snake_case       =  trie
														for i in range(_SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE				):
																					_snake_case       =  trie_node.get(string[i]							, _SCREAMING_SNAKE_CASE				)

																					if trie_node is None:
																												return False

																					if trie_node.get(_SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE				) and is_breakable(i + 1				):
																												return True

														return False

							return is_breakable(0				)


if __name__ == "__main__":
				import doctest

				doctest.testmod()

'''simple docstring'''
from __future__ import annotations






def  __SCREAMING_SNAKE_CASE				(  _SCREAMING_SNAKE_CASE				):
							_snake_case       =  len(_SCREAMING_SNAKE_CASE				)
							# We need to create solution object to save path.
							_snake_case       =  [[0 for _ in range(_SCREAMING_SNAKE_CASE				)] for _ in range(_SCREAMING_SNAKE_CASE				)]
							_snake_case       =  run_maze(_SCREAMING_SNAKE_CASE							, 0							, 0							, _SCREAMING_SNAKE_CASE				)
							if solved:
														print("""\n""".join(str(_SCREAMING_SNAKE_CASE				) for row in solutions				)				)
							else:
														print("""No solution exists!"""				)
							return solved






def  __SCREAMING_SNAKE_CASE				(  _SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE							, _SCREAMING_SNAKE_CASE				):
							_snake_case       =  len(_SCREAMING_SNAKE_CASE				)
							# Final check point.
							if i == j == (size - 1):
														_snake_case       =  1
														return True

							_snake_case       =  (not i < 0) and (not j < 0)  # Check lower bounds
							_snake_case       =  (i < size) and (j < size)  # Check upper bounds

							if lower_flag and upper_flag:
														# check for already visited and block points.
														_snake_case       =  (not solutions[i][j]) and (not maze[i][j])
														if block_flag:
																					# check visited
																					_snake_case       =  1

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

																					_snake_case       =  0
																					return False
							return False


if __name__ == "__main__":
				import doctest

				doctest.testmod()