




import multiprocessing
import os
from typing import BinaryIO, Optional, Union

from .. import Dataset, Features, NamedSplit, config
from ..formatting import query_table
from ..packaged_modules.csv.csv import Csv
from ..utils import logging
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader
class      _UpperCamelCase (			lowerCAmelCase						):
      def __init__(     self				:Optional[Any]	, lowerCamelCase				:NestedDataStructureLike[PathLike]	, lowerCamelCase				:Optional[NamedSplit] = None	, lowerCamelCase				:Optional[Features] = None	, lowerCamelCase				:str = None	, lowerCamelCase				:bool = False	, lowerCamelCase				:bool = False	, lowerCamelCase				:Optional[int] = None	, **lowerCamelCase				:Any	, )       ->     List[Any]:
       super().__init__(
           lowerCamelCase	, split=lowerCamelCase	, features=lowerCamelCase	, cache_dir=lowerCamelCase	, keep_in_memory=lowerCamelCase	, streaming=lowerCamelCase	, num_proc=lowerCamelCase	, **lowerCamelCase	, )
       UpperCAmelCase__								=  path_or_paths if isinstance(lowerCamelCase	, lowerCamelCase ) else {self.split: path_or_paths}
       UpperCAmelCase__								=  Csv(
           cache_dir=lowerCamelCase	, data_files=lowerCamelCase	, features=lowerCamelCase	, **lowerCamelCase	, )







      def 		UpperCAmelCase_  (     self				:Optional[int] )       ->     Tuple:
       # Build iterable dataset
       if self.streaming:
        UpperCAmelCase__								=  self.builder.as_streaming_dataset(split=self.split )
       # Build regular (map-style) dataset
       else:
        UpperCAmelCase__								=  None
        UpperCAmelCase__								=  None
        UpperCAmelCase__								=  None
        UpperCAmelCase__								=  None

        self.builder.download_and_prepare(
            download_config=lowerCamelCase	, download_mode=lowerCamelCase	, verification_mode=lowerCamelCase	, base_path=lowerCamelCase	, num_proc=self.num_proc	, )
        UpperCAmelCase__								=  self.builder.as_dataset(
            split=self.split	, verification_mode=lowerCamelCase	, in_memory=self.keep_in_memory )
       return dataset



class      _UpperCamelCase :
      def __init__(     self				:List[Any]	, lowerCamelCase				:Dataset	, lowerCamelCase				:Union[PathLike, BinaryIO]	, lowerCamelCase				:Optional[int] = None	, lowerCamelCase				:Optional[int] = None	, **lowerCamelCase				:Optional[Any]	, )       ->     int:
       if num_proc is not None and num_proc <= 0:
        raise ValueError(f'''num_proc {num_proc} must be an integer > 0.''' )

       UpperCAmelCase__								=  dataset
       UpperCAmelCase__								=  path_or_buf
       UpperCAmelCase__								=  batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
       UpperCAmelCase__								=  num_proc
       UpperCAmelCase__								=  "utf-8"
       UpperCAmelCase__								=  to_csv_kwargs
      def 		UpperCAmelCase_  (     self				:Dict )       ->     int:
       UpperCAmelCase__								=  self.to_csv_kwargs.pop("path_or_buf"	, lowerCamelCase )
       UpperCAmelCase__								=  self.to_csv_kwargs.pop("header"	, lowerCamelCase )
       UpperCAmelCase__								=  self.to_csv_kwargs.pop("index"	, lowerCamelCase )

       if isinstance(self.path_or_buf	, (str, bytes, os.PathLike) ):
        with open(self.path_or_buf	, "wb+" ) as buffer:
         UpperCAmelCase__								=  self._write(file_obj=lowerCamelCase	, header=lowerCamelCase	, index=lowerCamelCase	, **self.to_csv_kwargs )
       else:
        UpperCAmelCase__								=  self._write(file_obj=self.path_or_buf	, header=lowerCamelCase	, index=lowerCamelCase	, **self.to_csv_kwargs )
       return written
      def 		UpperCAmelCase_  (     self				:Dict	, lowerCamelCase				:List[Any] )       ->     str:
       UpperCAmelCase__	,	UpperCAmelCase__	,	UpperCAmelCase__	,	UpperCAmelCase__								=  args

       UpperCAmelCase__								=  query_table(
           table=self.dataset.data	, key=slice(lowerCamelCase	, offset + self.batch_size )	, indices=self.dataset._indices	, )
       UpperCAmelCase__								=  batch.to_pandas().to_csv(
           path_or_buf=lowerCamelCase	, header=header if (offset == 0) else False	, index=lowerCamelCase	, **lowerCamelCase )
       return csv_str.encode(self.encoding )







      def 		UpperCAmelCase_  (     self				:List[str]	, lowerCamelCase				:BinaryIO	, lowerCamelCase				:str	, lowerCamelCase				:Any	, **lowerCamelCase				:Any )       ->     int:
       UpperCAmelCase__								=  0

       if self.num_proc is None or self.num_proc == 1:
        for offset in logging.tqdm(
            range(0	, len(self.dataset )	, self.batch_size )	, unit="ba"	, disable=not logging.is_progress_bar_enabled()	, desc="Creating CSV from Arrow format"	, ):
         UpperCAmelCase__								=  self._batch_csv((offset, header, index, to_csv_kwargs) )
         written += file_obj.write(lowerCamelCase )

       else:
        UpperCAmelCase__	,	UpperCAmelCase__								=  len(self.dataset ), self.batch_size
        with multiprocessing.Pool(self.num_proc ) as pool:
         for csv_str in logging.tqdm(
             pool.imap(
                 self._batch_csv	, [(offset, header, index, to_csv_kwargs) for offset in range(0	, lowerCamelCase	, lowerCamelCase )]	, )	, total=(num_rows // batch_size) + 1 if num_rows % batch_size else num_rows // batch_size	, unit="ba"	, disable=not logging.is_progress_bar_enabled()	, desc="Creating CSV from Arrow format"	, ):
          written += file_obj.write(lowerCamelCase )

       return written











from collections import defaultdict



def   lowerCAmelCase						(						_lowerCAmelCase							:				int = 5		):




 """simple docstring"""







 UpperCAmelCase__								=  defaultdict(_lowerCAmelCase		)
 UpperCAmelCase__								=  0

 while True:
  UpperCAmelCase__								=  get_digits(_lowerCAmelCase		)
  freqs[digits].append(_lowerCAmelCase		)

  if len(freqs[digits]		) == max_base:
   UpperCAmelCase__								=  freqs[digits][0] ** 3
   return base

  num += 1



def   lowerCAmelCase						(						_lowerCAmelCase							:				int		):




 """simple docstring"""







 return "".join(sorted(str(num**3		)		)		)


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





