import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter





class 	_lowercase		(      TensorFormatter[Mapping, np.ndarray, Mapping] ):

 def __init__(				self			:							List[str]     ,   snake_case			:							Optional[int]=None     ,   **snake_case			:							Union[str, Any]    )     ->		Any:

  """simple docstring"""





  super().__init__(features=snake_case    )
  UpperCamelCase_      :		int				=      np_array_kwargs

 def 		SCREAMING_SNAKE_CASE__     (				self			:							Dict     ,   snake_case			:							int    )     ->		str:

  """simple docstring"""





  if isinstance(snake_case     ,   snake_case    ):
   if column and all(
       isinstance(snake_case     ,   np.ndarray    ) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column    ):
    return np.stack(snake_case    )
   else:
    # don't use np.array(column, dtype=object)
    # since it fails in certain cases
    # see https://stackoverflow.com/q/51005699
    UpperCamelCase_      :		Any				=      np.empty(len(snake_case    )     ,   dtype=snake_case    )
    UpperCamelCase_      :		Tuple				=      column
    return out
  return column

 def 		SCREAMING_SNAKE_CASE__     (				self			:							Dict     ,   snake_case			:							List[Any]    )     ->		List[Any]:

  """simple docstring"""





  if isinstance(snake_case     ,   (str, bytes, type(snake_case    ))    ):
   return value
  elif isinstance(snake_case     ,   (np.character, np.ndarray)    ) and np.issubdtype(value.dtype     ,   np.character    ):
   return value
  elif isinstance(snake_case     ,   np.number    ):
   return value

  UpperCamelCase_      :		Union[str, Any]				=      {}

  if isinstance(snake_case     ,   np.ndarray    ) and np.issubdtype(value.dtype     ,   np.integer    ):
   UpperCamelCase_      :		Optional[int]				=      {'dtype': np.intaa}
  elif isinstance(snake_case     ,   np.ndarray    ) and np.issubdtype(value.dtype     ,   np.floating    ):
   UpperCamelCase_      :		List[str]				=      {'dtype': np.floataa}
  elif config.PIL_AVAILABLE and "PIL" in sys.modules:
   import PIL.Image

   if isinstance(snake_case     ,   PIL.Image.Image    ):
    return np.asarray(snake_case     ,   **self.np_array_kwargs    )

  return np.asarray(snake_case     ,   **{**default_dtype, **self.np_array_kwargs}    )

 def 		SCREAMING_SNAKE_CASE__     (				self			:							Any     ,   snake_case			:							str    )     ->		Optional[Any]:

  """simple docstring"""





  if config.TORCH_AVAILABLE and "torch" in sys.modules:
   import torch

   if isinstance(snake_case     ,   torch.Tensor    ):
    return self._tensorize(data_struct.detach().cpu().numpy()[()]    )
  if hasattr(snake_case     ,   '__array__'    ) and not isinstance(snake_case     ,   (np.ndarray, np.character, np.number)    ):
   UpperCamelCase_      :		Optional[int]				=      data_struct.__array__()
  # support for nested types like struct of list of struct
  if isinstance(snake_case     ,   np.ndarray    ):
   if data_struct.dtype == object:
    return self._consolidate([self.recursive_tensorize(snake_case    ) for substruct in data_struct]    )
  if isinstance(snake_case     ,   (list, tuple)    ):
   return self._consolidate([self.recursive_tensorize(snake_case    ) for substruct in data_struct]    )
  return self._tensorize(snake_case    )

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

  """simple docstring"""





  return map_nested(self._recursive_tensorize     ,   snake_case     ,   map_list=snake_case    )

 def 		SCREAMING_SNAKE_CASE__     (				self			:							Optional[Any]     ,   snake_case			:							pa.Table    )     ->		Mapping:

  """simple docstring"""





  UpperCamelCase_      :		Tuple				=      self.numpy_arrow_extractor().extract_row(snake_case    )
  UpperCamelCase_      :		Optional[int]				=      self.python_features_decoder.decode_row(snake_case    )
  return self.recursive_tensorize(snake_case    )

 def 		SCREAMING_SNAKE_CASE__     (				self			:							Any     ,   snake_case			:							pa.Table    )     ->		np.ndarray:

  """simple docstring"""





  UpperCamelCase_      :		Tuple				=      self.numpy_arrow_extractor().extract_column(snake_case    )
  UpperCamelCase_      :		int				=      self.python_features_decoder.decode_column(snake_case     ,   pa_table.column_names[0]    )
  UpperCamelCase_      :		List[Any]				=      self.recursive_tensorize(snake_case    )
  UpperCamelCase_      :		int				=      self._consolidate(snake_case    )
  return column


 def 		SCREAMING_SNAKE_CASE__     (				self			:							Optional[Any]     ,   snake_case			:							pa.Table    )     ->		Mapping:

  """simple docstring"""





  UpperCamelCase_      :		Optional[int]				=      self.numpy_arrow_extractor().extract_batch(snake_case    )
  UpperCamelCase_      :		List[Any]				=      self.python_features_decoder.decode_batch(snake_case    )
  UpperCamelCase_      :		Any				=      self.recursive_tensorize(snake_case    )
  for column_name in batch:
   UpperCamelCase_      :		int				=      self._consolidate(batch[column_name]    )
  return batch




def      __lowercase  (		lowerCamelCase      :  int = 998001			):
 UpperCamelCase_      :		int				=      0
 for i in range(999						,						99						,						-1			):  # 3 digit numbers range from 999 down to 100
  for j in range(999						,						99						,						-1			):
   UpperCamelCase_      :		str				=      str(i * j			)
   if product_string == product_string[::-1] and i * j < n:
    UpperCamelCase_      :		str				=      max(lowerCamelCase						,						i * j			)
 return answer


if __name__ == "__main__":
   print(F"""{solution() = }""")



