
"""simple docstring"""




import itertools
from dataclasses import dataclass
from typing import Optional

import pyarrow as pa

import datasets
from datasets.table import table_cast


_A      :	Tuple       		=	datasets.utils.logging.get_logger(__name__)

@dataclass
class 		a__						(				datasets.BuilderConfig						):
      __lowerCAmelCase						=    None


class 		a__						(				datasets.ArrowBasedBuilder						):
      __lowerCAmelCase						=    ArrowConfig
      def       __magic_name__      (      self    ):
             return datasets.DatasetInfo(features=self.config.features    )
      def       __magic_name__      (      self     ,   _a    ):
             if not self.config.data_files:
                    raise ValueError(f"""At least one data file must be specified, but got data_files={self.config.data_files}"""    )
             lowercase   :    Optional[int]			=							dl_manager.download_and_extract(self.config.data_files    )
             if isinstance(_a     ,   (str, list, tuple)    ):
                    lowercase   :    List[str]			=							data_files
                    if isinstance(_a     ,   _a    ):
                           lowercase   :    List[str]			=							[files]
                    # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
                    lowercase   :    Union[str, Any]			=							[dl_manager.iter_files(_a    ) for file in files]
                    return [datasets.SplitGenerator(name=datasets.Split.TRAIN     ,   gen_kwargs={"files": files}    )]
             lowercase   :    Optional[Any]			=							[]
             for split_name, files in data_files.items():
                    if isinstance(_a     ,   _a    ):
                           lowercase   :    Dict			=							[files]
                    # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
                    lowercase   :    List[str]			=							[dl_manager.iter_files(_a    ) for file in files]
                    # Infer features is they are stoed in the arrow schema
                    if self.info.features is None:
                           for file in itertools.chain.from_iterable(_a    ):
                                  with open(_a     ,   "rb"    ) as f:
                                         lowercase   :    List[Any]			=							datasets.Features.from_arrow_schema(pa.ipc.open_stream(_a    ).schema    )
                                  break
                    splits.append(datasets.SplitGenerator(name=_a     ,   gen_kwargs={"files": files}    )    )
             return splits
      def       __magic_name__      (      self     ,   _a    ):
             if self.info.features is not None:
                    # more expensive cast to support nested features with keys in a different order
                    # allows str <-> int/float or str to Audio for example
                    lowercase   :    Dict			=							table_cast(_a     ,   self.info.features.arrow_schema    )
             return pa_table

      def       __magic_name__      (      self     ,   _a    ):
             for file_idx, file in enumerate(itertools.chain.from_iterable(_a    )    ):
                    with open(_a     ,   "rb"    ) as f:
                           try:
                                  for batch_idx, record_batch in enumerate(pa.ipc.open_stream(_a    )    ):
                                         lowercase   :    List[Any]			=							pa.Table.from_batches([record_batch]    )
                                         # Uncomment for debugging (will print the Arrow table size and elements)
                                         # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
                                         # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
                                         yield f"""{file_idx}_{batch_idx}""", self._cast_table(_a    )
                           except ValueError as e:
                                  logger.error(f"""Failed to read file \'{file}\' with error {type(_a    )}: {e}"""    )
                                  raise




"""simple docstring"""




from __future__ import annotations

_A      :	List[str]       		=	"""Alexander Joslin"""


def   __magic_name__     (				__snake_case    :	int  )			->    int:

       if number <= 0:
              lowercase   :    Optional[Any]			=							f"""n must be greater than 0. Got n = {number}"""
              raise ValueError(__snake_case  )

       lowercase   :    List[str]			=							[number + 1] * (number + 1)

       # starting position
       lowercase   :    Optional[Any]			=							0
       for i in range(1					,			__snake_case  ):
              lowercase   :    str			=							min(table[i + 1]					,			table[i] + 1  )
              # check if out of bounds
              if i * 2 <= number:
                     lowercase   :    int			=							min(table[i * 2]					,			table[i] + 1  )
              # check if out of bounds
              if i * 3 <= number:
                     lowercase   :    Optional[int]			=							min(table[i * 3]					,			table[i] + 1  )
       return table[number]


if __name__ == "__main__":
   import doctest

   doctest.testmod()


