





import importlib.metadata
import subprocess
import sys




def  A_(      A = False ):
	UpperCAmelCase_		    =  False
	if "IPython" in sys.modules:
		UpperCAmelCase_		    =  'google.colab' in str(sys.modules["""IPython"""].get_ipython() )

	if in_colab:
		if upgrade:
			UpperCAmelCase_		    =  ['pip', 'install', '-U', 'torch']
			subprocess.run(UpperCamelCase_					,   check=UpperCamelCase_ )
		# get the current version of torch
		UpperCAmelCase_		    =  importlib.metadata.version("""torch""" )
		UpperCAmelCase_		    =  torch_version[: torch_version.rindex(""".""" )]
		UpperCAmelCase_		    =  f"""https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl"""
		UpperCAmelCase_		    =  ['pip', 'install', xla_wheel]
		subprocess.run(UpperCamelCase_					,   check=UpperCamelCase_ )
	else:
		raise RuntimeError("""`install_xla` utility works only on google colab.""" )










"""simple docstring"""


def 					a			(  UpperCamelCase_				:					int  ,						UpperCamelCase_				:					int  ,						UpperCamelCase_				:					int  ,						UpperCamelCase_				:					int		)	->		int:
 return len_board * len_board_column * row + column




def 					a			(  UpperCamelCase_				:					list[list[str]]  ,						UpperCamelCase_				:					str  ,						UpperCamelCase_				:					int  ,						UpperCamelCase_				:					int  ,						UpperCamelCase_				:					int  ,						UpperCamelCase_				:					set[int]  ,						)	->		bool:

 if board[row][column] != word[word_index]:
  return False

 if word_index == len(UpperCamelCase_		) - 1:
  return True

 __A						:							List[str]      =						[(0, 1), (0, -1), (-1, 0), (1, 0)]
 __A						:							Any      =						len(UpperCamelCase_		)
 __A						:							Union[str, Any]      =						len(board[0]		)
 for direction in traverts_directions:
  __A						:							Any      =						row + direction[0]
  __A						:							List[Any]      =						column + direction[1]
  if not (0 <= next_i < len_board and 0 <= next_j < len_board_column):
   continue

  __A						:							Any      =						get_point_key(UpperCamelCase_  ,						UpperCamelCase_  ,						UpperCamelCase_  ,						UpperCamelCase_		)
  if key in visited_points_set:
   continue

  visited_points_set.add(UpperCamelCase_		)
  if exits_word(UpperCamelCase_  ,						UpperCamelCase_  ,						UpperCamelCase_  ,						UpperCamelCase_  ,						word_index + 1  ,						UpperCamelCase_		):
   return True

  visited_points_set.remove(UpperCamelCase_		)

 return False




def 					a			(  UpperCamelCase_				:					list[list[str]]  ,						UpperCamelCase_				:					str		)	->		bool:
 __A						:							Optional[Any]      =						(
     'The board should be a non empty matrix of single chars strings.'
 )

 __A						:							Dict      =						len(UpperCamelCase_		)
 if not isinstance(UpperCamelCase_  ,						UpperCamelCase_		) or len(UpperCamelCase_		) == 0:
  raise ValueError(UpperCamelCase_		)

 for row in board:
  if not isinstance(UpperCamelCase_  ,						UpperCamelCase_		) or len(UpperCamelCase_		) == 0:
   raise ValueError(UpperCamelCase_		)

  for item in row:
   if not isinstance(UpperCamelCase_  ,						UpperCamelCase_		) or len(UpperCamelCase_		) != 1:
    raise ValueError(UpperCamelCase_		)

    # Validate word
 if not isinstance(UpperCamelCase_  ,						UpperCamelCase_		) or len(UpperCamelCase_		) == 0:
  raise ValueError(
      'The word parameter should be a string of length greater than 0.'		)

 __A						:							List[Any]      =						len(board[0]		)
 for i in range(UpperCamelCase_		):
  for j in range(UpperCamelCase_		):
   if exits_word(
       UpperCamelCase_  ,						UpperCamelCase_  ,						UpperCamelCase_  ,						UpperCamelCase_  ,						0  ,						{get_point_key(UpperCamelCase_  ,						UpperCamelCase_  ,						UpperCamelCase_  ,						UpperCamelCase_		)}		):
    return True

 return False


if __name__ == "__main__":
   import doctest

   doctest.testmod()





