





'''simple docstring'''

import itertools
from dataclasses import dataclass
from typing import Optional

import pyarrow as pa

import datasets
from datasets.table import table_cast


lowerCAmelCase__	:					Dict	     =       datasets.utils.logging.get_logger(__name__)


@dataclass
class 			SCREAMING_SNAKE_CASE__	(					datasets.BuilderConfig						):







					"""simple docstring"""






					SCREAMING_SNAKE_CASE				=     None






class 			SCREAMING_SNAKE_CASE__	(					datasets.ArrowBasedBuilder						):







					"""simple docstring"""






					SCREAMING_SNAKE_CASE				=     ArrowConfig
					def 						lowerCamelCase_					(					self    :	Tuple						):







							"""simple docstring"""
							return datasets.DatasetInfo(features=self.config.features						)
					def 						lowerCamelCase_					(					self    :	Optional[int]						,     UpperCAmelCase_    :	Dict						):







							"""simple docstring"""


							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}"						)
							__UpperCAmelCase     :				Optional[int]					   =			dl_manager.download_and_extract(self.config.data_files						)
							if isinstance(lowerCAmelCase_						,     (str, list, tuple)						):
									__UpperCAmelCase     :				Optional[Any]					   =			data_files
									if isinstance(lowerCAmelCase_						,     lowerCAmelCase_						):
											__UpperCAmelCase     :				Any					   =			[files]
									# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
									__UpperCAmelCase     :				Tuple					   =			[dl_manager.iter_files(lowerCAmelCase_						) for file in files]
									return [datasets.SplitGenerator(name=datasets.Split.TRAIN						,     gen_kwargs={"files": files}						)]
							__UpperCAmelCase     :				Any					   =			[]
							for split_name, files in data_files.items():
									if isinstance(lowerCAmelCase_						,     lowerCAmelCase_						):
											__UpperCAmelCase     :				Any					   =			[files]
									# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
									__UpperCAmelCase     :				Tuple					   =			[dl_manager.iter_files(lowerCAmelCase_						) 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(lowerCAmelCase_						):
													with open(lowerCAmelCase_						,     "rb"						) as f:
															__UpperCAmelCase     :				List[str]					   =			datasets.Features.from_arrow_schema(pa.ipc.open_stream(lowerCAmelCase_						).schema						)
													break
									splits.append(datasets.SplitGenerator(name=lowerCAmelCase_						,     gen_kwargs={"files": files}						)						)
							return splits
					def 						lowerCamelCase_					(					self    :	Any						,     UpperCAmelCase_    :	pa.Table						):







							"""simple docstring"""


							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
									__UpperCAmelCase     :				Dict					   =			table_cast(lowerCAmelCase_						,     self.info.features.arrow_schema						)
							return pa_table






					def 						lowerCamelCase_					(					self    :	Optional[int]						,     UpperCAmelCase_    :	Union[str, Any]						):







							"""simple docstring"""


							for file_idx, file in enumerate(itertools.chain.from_iterable(lowerCAmelCase_						)						):
									with open(lowerCAmelCase_						,     "rb"						) as f:
											try:
													for batch_idx, record_batch in enumerate(pa.ipc.open_stream(lowerCAmelCase_						)						):
															__UpperCAmelCase     :				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(lowerCAmelCase_						)
											except ValueError as e:
													logger.error(f"Failed to read file \'{file}\' with error {type(lowerCAmelCase_						)}: {e}"						)
													raise










'''simple docstring'''


from __future__ import annotations
def 		snake_case_    (UpperCamelCase       :  int      ):





							'''simple docstring'''


							_a	     =				[0] * max_one

							for i in range(0 ,						UpperCamelCase      ):
														_a	     =				i

							for i in range(2 ,						UpperCamelCase      ):
														if totients[i] == i:
																					for j in range(UpperCamelCase ,						UpperCamelCase ,						UpperCamelCase      ):
																												totients[j] -= totients[j] // i

							return totients
def 		snake_case_    (UpperCamelCase       :  int ,						UpperCamelCase       :  int      ):





							'''simple docstring'''


							return sorted(str(UpperCamelCase      )      ) == sorted(str(UpperCamelCase      )      )
def 		snake_case_    (UpperCamelCase       :  int = 1000_0000      ):





							'''simple docstring'''


							_a	     =				1  # i
							_a	     =				0  # φ(i)
							_a	     =				get_totients(max_n + 1      )

							for i in range(2 ,						max_n + 1      ):
														_a	     =				totients[i]

														if i * min_denominator < min_numerator * t and has_same_digits(UpperCamelCase ,						UpperCamelCase      ):
																					_a	     =				i
																					_a	     =				t

							return min_numerator


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

