





from __future__ import annotations

from collections.abc import Iterable, Iterator
from typing import Any, Generic, TypeVar

UpperCamelCase_     =TypeVar("""T""", bound=bool)




class 				_a		(   Generic[T]       ):






				def __init__(				self	:					Any,				lowerCAmelCase__	:					T							)			->   None:




										'''simple docstring'''



										_UpperCamelCase    :      T						     =					value
										_UpperCamelCase    :      SkewNode[T] | None						     =					None
										_UpperCamelCase    :      SkewNode[T] | None						     =					None






				@property
				def        snake_case			(				self	:					List[Any]							)			->   T:




										'''simple docstring'''



										return self._value






				@staticmethod
				def        snake_case			(				lowerCAmelCase__	:					SkewNode[T] | None,				lowerCAmelCase__	:					SkewNode[T] | None							)			->   SkewNode[T] | None:




										'''simple docstring'''



										if not roota:
																return roota

										if not roota:
																return roota

										if roota.value > roota.value:
																_UpperCamelCase    :      Tuple						     =					roota, roota

										_UpperCamelCase    :      List[str]						     =					roota
										_UpperCamelCase    :      str						     =					roota.right
										_UpperCamelCase    :      Optional[Any]						     =					roota.left
										_UpperCamelCase    :      int						     =					SkewNode.merge(lowerCAmelCase__,				lowerCAmelCase__							)

										return result




class 				_a		(   Generic[T]       ):






				def __init__(				self	:					Optional[Any],				lowerCAmelCase__	:					Iterable[T] | None = ()							)			->   None:




										'''simple docstring'''



										_UpperCamelCase    :      SkewNode[T] | None						     =					None
										if data:
																for item in data:
																						self.insert(lowerCAmelCase__							)






				def __bool__(				self	:					Union[str, Any]							)			->   bool:




										'''simple docstring'''



										return self._root is not None






				def __iter__(				self	:					Tuple							)			->   Iterator[T]:




										'''simple docstring'''



										_UpperCamelCase    :      list[Any]						     =					[]
										while self:
																result.append(self.pop()							)

										# Pushing items back to the heap not to clear it.
										for item in result:
																self.insert(lowerCAmelCase__							)

										return iter(lowerCAmelCase__							)






				def        snake_case			(				self	:					List[str],				lowerCAmelCase__	:					T							)			->   None:




										'''simple docstring'''



										_UpperCamelCase    :      Tuple						     =					SkewNode.merge(self._root,				SkewNode(lowerCAmelCase__							)							)






				def        snake_case			(				self	:					Any							)			->   T | None:




										'''simple docstring'''



										_UpperCamelCase    :      int						     =					self.top()
										_UpperCamelCase    :      Dict						     =					(
										    SkewNode.merge(self._root.left,				self._root.right							) if self._root else None
										)

										return result






				def        snake_case			(				self	:					Tuple							)			->   T:




										'''simple docstring'''



										if not self._root:
																raise IndexError('''Can\'t get top element for the empty heap.'''							)
										return self._root.value






				def        snake_case			(				self	:					Union[str, Any]							)			->   None:




										'''simple docstring'''



										_UpperCamelCase    :      List[str]						     =					None


if __name__ == "__main__":
						import doctest

						doctest.testmod()










"""simple docstring"""




def  a_       (							_lowercase ,		_lowercase ,		_lowercase ,		_lowercase     ):
						return len_board * len_board_column * row + column





def  a_       (							_lowercase ,		_lowercase ,		_lowercase ,		_lowercase ,		_lowercase ,		_lowercase ,		):

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

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

						_UpperCamelCase    :      Union[str, Any]						     =					[(0, 1), (0, -1), (-1, 0), (1, 0)]
						_UpperCamelCase    :      List[str]						     =					len(_lowercase     )
						_UpperCamelCase    :      Optional[Any]						     =					len(board[0]     )
						for direction in traverts_directions:
												_UpperCamelCase    :      Union[str, Any]						     =					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[Any]						     =					get_point_key(_lowercase ,		_lowercase ,		_lowercase ,		_lowercase     )
												if key in visited_points_set:
																		continue

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

												visited_points_set.remove(_lowercase     )

						return False





def  a_       (							_lowercase ,		_lowercase     ):
						_UpperCamelCase    :      Optional[Any]						     =					(
						    '''The board should be a non empty matrix of single chars strings.'''
						)

						_UpperCamelCase    :      int						     =					len(_lowercase     )
						if not isinstance(_lowercase ,		_lowercase     ) or len(_lowercase     ) == 0:
												raise ValueError(_lowercase     )

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

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

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

						_UpperCamelCase    :      List[str]						     =					len(board[0]     )
						for i in range(_lowercase     ):
												for j in range(_lowercase     ):
																		if exits_word(
																		    _lowercase ,		_lowercase ,		_lowercase ,		_lowercase ,		0 ,		{get_point_key(_lowercase ,		_lowercase ,		_lowercase ,		_lowercase     )}     ):
																								return True

						return False


if __name__ == "__main__":
						import doctest

						doctest.testmod()



