

def  _snake_case		(snake_case_					:     int    ,       snake_case_					:     int    ,       snake_case_					:     int    ,       snake_case_					:     int  )							->		int:
  return len_board * len_board_column * row + column





def  _snake_case		(snake_case_					:     list[list[str]]    ,       snake_case_					:     str    ,       snake_case_					:     int    ,       snake_case_					:     int    ,       snake_case_					:     int    ,       snake_case_					:     set[int]    ,       )							->		bool:

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

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

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

    __UpperCAmelCase	:  Optional[int]		=     get_point_key(snake_case_    ,       snake_case_    ,       snake_case_    ,       snake_case_  )
    if key in visited_points_set:
      continue

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

    visited_points_set.remove(snake_case_  )

  return False





def  _snake_case		(snake_case_					:     list[list[str]]    ,       snake_case_					:     str  )							->		bool:
  __UpperCAmelCase	:  int		=     (
      'The board should be a non empty matrix of single chars strings.'
  )

  __UpperCAmelCase	:  Union[str, Any]		=     len(snake_case_  )
  if not isinstance(snake_case_    ,       snake_case_  ) or len(snake_case_  ) == 0:
    raise ValueError(snake_case_  )

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

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

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

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

  return False


if __name__ == "__main__":
      import doctest

      doctest.testmod()







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


snake_case_      :					Any				      =     {
    'configuration_imagegpt': ['IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ImageGPTConfig', 'ImageGPTOnnxConfig']
}

try:
	if not is_vision_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	snake_case_      :					str				      =     ['ImageGPTFeatureExtractor']
	snake_case_      :					Optional[int]				      =     ['ImageGPTImageProcessor']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	snake_case_      :					List[str]				      =     [
	    'IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'ImageGPTForCausalImageModeling',
	    'ImageGPTForImageClassification',
	    'ImageGPTModel',
	    'ImageGPTPreTrainedModel',
	    'load_tf_weights_in_imagegpt',
	]


if TYPE_CHECKING:
	from .configuration_imagegpt import IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP, ImageGPTConfig, ImageGPTOnnxConfig

	try:
		if not is_vision_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .feature_extraction_imagegpt import ImageGPTFeatureExtractor
		from .image_processing_imagegpt import ImageGPTImageProcessor

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_imagegpt import (
		    IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    ImageGPTForCausalImageModeling,
		    ImageGPTForImageClassification,
		    ImageGPTModel,
		    ImageGPTPreTrainedModel,
		    load_tf_weights_in_imagegpt,
		)

else:
	import sys

	snake_case_      :					Dict				      =     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
