


'''simple docstring'''







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 A__	(						UpperCAmelCase__				):






      def __init__(			self      :List[Any]					,						SCREAMING_SNAKE_CASE      :NestedDataStructureLike[PathLike]					,						SCREAMING_SNAKE_CASE      :Optional[NamedSplit] = None					,						SCREAMING_SNAKE_CASE      :Optional[Features] = None					,						SCREAMING_SNAKE_CASE      :str = None					,						SCREAMING_SNAKE_CASE      :bool = False					,						SCREAMING_SNAKE_CASE      :bool = False					,						SCREAMING_SNAKE_CASE      :Optional[int] = None					,						**SCREAMING_SNAKE_CASE      :Union[str, Any]					,						)	-> Optional[int]:




             '''simple docstring'''
             super().__init__(
                 SCREAMING_SNAKE_CASE					,						split=SCREAMING_SNAKE_CASE					,						features=SCREAMING_SNAKE_CASE					,						cache_dir=SCREAMING_SNAKE_CASE					,						keep_in_memory=SCREAMING_SNAKE_CASE					,						streaming=SCREAMING_SNAKE_CASE					,						num_proc=SCREAMING_SNAKE_CASE					,						**SCREAMING_SNAKE_CASE					,						)
             _a   :			List[str]					 =path_or_paths if isinstance(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     ) else {self.split: path_or_paths}
             _a   :			Union[str, Any]					 =Csv(
                 cache_dir=SCREAMING_SNAKE_CASE					,						data_files=SCREAMING_SNAKE_CASE					,						features=SCREAMING_SNAKE_CASE					,						**SCREAMING_SNAKE_CASE					,						)






      def __UpperCAmelCase	(			self      :str     )	-> Tuple:




             '''simple docstring'''
             # Build iterable dataset
             if self.streaming:
                    _a   :			List[Any]					 =self.builder.as_streaming_dataset(split=self.split     )
             # Build regular (map-style) dataset
             else:
                    _a   :			Optional[Any]					 =None
                    _a   :			Dict					 =None
                    _a   :			Optional[int]					 =None
                    _a   :			Any					 =None

                    self.builder.download_and_prepare(
                        download_config=SCREAMING_SNAKE_CASE					,						download_mode=SCREAMING_SNAKE_CASE					,						verification_mode=SCREAMING_SNAKE_CASE					,						base_path=SCREAMING_SNAKE_CASE					,						num_proc=self.num_proc					,						)
                    _a   :			Any					 =self.builder.as_dataset(
                        split=self.split					,						verification_mode=SCREAMING_SNAKE_CASE					,						in_memory=self.keep_in_memory     )
             return dataset







class A__	:






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




             '''simple docstring'''
             if num_proc is not None and num_proc <= 0:
                    raise ValueError(f"num_proc {num_proc} must be an integer > 0."     )

             _a   :			str					 =dataset
             _a   :			int					 =path_or_buf
             _a   :			Union[str, Any]					 =batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
             _a   :			Dict					 =num_proc
             _a   :			int					 ="""utf-8"""
             _a   :			Tuple					 =to_csv_kwargs






      def __UpperCAmelCase	(			self      :Tuple     )	-> int:




             '''simple docstring'''
             _a   :			Union[str, Any]					 =self.to_csv_kwargs.pop("""path_or_buf"""					,						SCREAMING_SNAKE_CASE     )
             _a   :			Any					 =self.to_csv_kwargs.pop("""header"""					,						SCREAMING_SNAKE_CASE     )
             _a   :			Optional[int]					 =self.to_csv_kwargs.pop("""index"""					,						SCREAMING_SNAKE_CASE     )

             if isinstance(self.path_or_buf					,						(str, bytes, os.PathLike)     ):
                    with open(self.path_or_buf					,						"""wb+"""     ) as buffer:
                           _a   :			Any					 =self._write(file_obj=SCREAMING_SNAKE_CASE					,						header=SCREAMING_SNAKE_CASE					,						index=SCREAMING_SNAKE_CASE					,						**self.to_csv_kwargs     )
             else:
                    _a   :			int					 =self._write(file_obj=self.path_or_buf					,						header=SCREAMING_SNAKE_CASE					,						index=SCREAMING_SNAKE_CASE					,						**self.to_csv_kwargs     )
             return written






      def __UpperCAmelCase	(			self      :Union[str, Any]					,						SCREAMING_SNAKE_CASE      :Dict     )	-> Dict:




             '''simple docstring'''
             _a ,   _a ,   _a ,   _a   :			Optional[Any]					 =args

             _a   :			List[Any]					 =query_table(
                 table=self.dataset.data					,						key=slice(SCREAMING_SNAKE_CASE					,						offset + self.batch_size     )					,						indices=self.dataset._indices					,						)
             _a   :			str					 =batch.to_pandas().to_csv(
                 path_or_buf=SCREAMING_SNAKE_CASE					,						header=header if (offset == 0) else False					,						index=SCREAMING_SNAKE_CASE					,						**SCREAMING_SNAKE_CASE     )
             return csv_str.encode(self.encoding     )






      def __UpperCAmelCase	(			self      :List[str]					,						SCREAMING_SNAKE_CASE      :BinaryIO					,						SCREAMING_SNAKE_CASE      :Union[str, Any]					,						SCREAMING_SNAKE_CASE      :int					,						**SCREAMING_SNAKE_CASE      :Optional[int]     )	-> int:




             '''simple docstring'''
             _a   :			Optional[Any]					 =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"""					,						):
                           _a   :			List[Any]					 =self._batch_csv((offset, header, index, to_csv_kwargs)     )
                           written += file_obj.write(SCREAMING_SNAKE_CASE     )

             else:
                    _a ,   _a   :			Optional[int]					 =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					,						SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )]					,						)					,						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(SCREAMING_SNAKE_CASE     )

             return written






'''simple docstring'''







import math


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     int  )  ->      int:
       return sum(int(_UpperCAmelCase  ) for digit in str(_UpperCAmelCase  )  )


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     int = 30  )  ->      int:
       _a   :			List[Any]					 =[]
       for digit in range(2   ,100  ):
              for power in range(2   ,100  ):
                     _a   :			Optional[Any]					 =int(math.pow(_UpperCAmelCase   ,_UpperCAmelCase  )  )
                     if digit == digit_sum(_UpperCAmelCase  ):
                            digit_to_powers.append(_UpperCAmelCase  )

       digit_to_powers.sort()
       return digit_to_powers[n - 1]


if __name__ == "__main__":
   print(solution())


