




import math
import time
from typing import Dict, List, Optional

from torch.utils.data import Dataset

from transformers import SeqaSeqTrainer, is_torch_tpu_available
from transformers.trainer_utils import PredictionOutput, speed_metrics


if is_torch_tpu_available(check_device=False):
  import torch_xla.core.xla_model as xm
  import torch_xla.debug.metrics as met







class 						lowercase							(   lowerCamelCase_		):

     def __init__(  self		,     *_a		,     _a=None		,     _a=None		,     **_a				)						->							Optional[int]:
           super().__init__(*__SCREAMING_SNAKE_CASE		,     **__SCREAMING_SNAKE_CASE				)
           _A							:     Tuple			=						eval_examples
           _A							:     Tuple			=						post_process_function

     def 					a__	(  self		,     _a = None		,     _a=None		,     _a = None		,     _a = "eval"		,     **_a		,     )						->							int:
           _A							:     Optional[int]			=						gen_kwargs.copy()
           _A							:     List[str]			=						(
               gen_kwargs['''max_length'''] if gen_kwargs.get("""max_length"""				) is not None else self.args.generation_max_length
           )
           _A							:     str			=						(
               gen_kwargs['''num_beams'''] if gen_kwargs.get("""num_beams"""				) is not None else self.args.generation_num_beams
           )
           _A							:     Dict			=						gen_kwargs

           _A							:     List[Any]			=						self.eval_dataset if eval_dataset is None else eval_dataset
           _A							:     List[str]			=						self.get_eval_dataloader(__SCREAMING_SNAKE_CASE				)
           _A							:     Optional[Any]			=						self.eval_examples if eval_examples is None else eval_examples

           # Temporarily disable metric computation, we will do it in the loop here.
           _A							:     Union[str, Any]			=						self.compute_metrics
           _A							:     Optional[int]			=						None
           _A							:     Tuple			=						time.time()
           _A							:     Tuple			=						self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
           try:
                 _A							:     str			=						eval_loop(
                     __SCREAMING_SNAKE_CASE		,     description="""Evaluation"""		,     prediction_loss_only=True if compute_metrics is None else None		,     ignore_keys=__SCREAMING_SNAKE_CASE		,     metric_key_prefix=__SCREAMING_SNAKE_CASE		,     )
           finally:
                 _A							:     Any			=						compute_metrics
           _A							:     Any			=						self.args.eval_batch_size * self.args.world_size
           if F'''{metric_key_prefix}_jit_compilation_time''' in output.metrics:
                 start_time += output.metrics[F'''{metric_key_prefix}_jit_compilation_time''']
           output.metrics.update(
               speed_metrics(
                   __SCREAMING_SNAKE_CASE		,     __SCREAMING_SNAKE_CASE		,     num_samples=output.num_samples		,     num_steps=math.ceil(output.num_samples / total_batch_size				)		,     )				)

           if self.post_process_function is not None and self.compute_metrics is not None and self.args.should_save:
                 # Only the main node write the results by default
                 _A							:     Optional[Any]			=						self.post_process_function(__SCREAMING_SNAKE_CASE		,     __SCREAMING_SNAKE_CASE		,     __SCREAMING_SNAKE_CASE				)
                 _A							:     Optional[int]			=						self.compute_metrics(__SCREAMING_SNAKE_CASE				)

                 # Prefix all keys with metric_key_prefix + '_'
                 for key in list(metrics.keys()				):
                       if not key.startswith(F'''{metric_key_prefix}_'''				):
                             _A							:     List[Any]			=						metrics.pop(__SCREAMING_SNAKE_CASE				)

                 metrics.update(output.metrics				)
           else:
                 _A							:     List[Any]			=						output.metrics

           if self.args.should_log:
                 # Only the main node log the results by default
                 self.log(__SCREAMING_SNAKE_CASE				)

           if self.args.tpu_metrics_debug or self.args.debug:
                 # tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.)
                 xm.master_print(met.metrics_report()				)

           _A							:     List[Any]			=						self.callback_handler.on_evaluate(self.args		,     self.state		,     self.control		,     __SCREAMING_SNAKE_CASE				)
           return metrics



     def 					a__	(  self		,     _a		,     _a		,     _a=None		,     _a = "test"		,     **_a				)						->							int:
           _A							:     Union[str, Any]			=						gen_kwargs.copy()

           _A							:     Tuple			=						self.get_test_dataloader(__SCREAMING_SNAKE_CASE				)

           # Temporarily disable metric computation, we will do it in the loop here.
           _A							:     Optional[Any]			=						self.compute_metrics
           _A							:     Optional[int]			=						None
           _A							:     List[Any]			=						time.time()
           _A							:     int			=						self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
           try:
                 _A							:     Tuple			=						eval_loop(
                     __SCREAMING_SNAKE_CASE		,     description="""Prediction"""		,     prediction_loss_only=True if compute_metrics is None else None		,     ignore_keys=__SCREAMING_SNAKE_CASE		,     metric_key_prefix=__SCREAMING_SNAKE_CASE		,     )
           finally:
                 _A							:     Any			=						compute_metrics

           _A							:     Tuple			=						self.args.eval_batch_size * self.args.world_size
           if F'''{metric_key_prefix}_jit_compilation_time''' in output.metrics:
                 start_time += output.metrics[F'''{metric_key_prefix}_jit_compilation_time''']
           output.metrics.update(
               speed_metrics(
                   __SCREAMING_SNAKE_CASE		,     __SCREAMING_SNAKE_CASE		,     num_samples=output.num_samples		,     num_steps=math.ceil(output.num_samples / total_batch_size				)		,     )				)
           if self.post_process_function is None or self.compute_metrics is None:
                 return output

           _A							:     Any			=						self.post_process_function(__SCREAMING_SNAKE_CASE		,     __SCREAMING_SNAKE_CASE		,     __SCREAMING_SNAKE_CASE		,     """predict"""				)
           _A							:     str			=						self.compute_metrics(__SCREAMING_SNAKE_CASE				)

           # Prefix all keys with metric_key_prefix + '_'
           for key in list(metrics.keys()				):
                 if not key.startswith(F'''{metric_key_prefix}_'''				):
                       _A							:     Optional[int]			=						metrics.pop(__SCREAMING_SNAKE_CASE				)
           metrics.update(output.metrics				)
           return PredictionOutput(predictions=predictions.predictions		,     label_ids=predictions.label_ids		,     metrics=__SCREAMING_SNAKE_CASE				)



'''simple docstring'''







_lowercase :  int    							=       [sum(int(c, 1_0) ** 2 for c in i.__str__()) for i in range(1_0_0_0_0_0)]
def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: int							):



						"""simple docstring"""





						lowercase_	:     Optional[int]													=       0
						while number:
												# Increased Speed Slightly by checking every 5 digits together.
												sum_of_digits_squared += DIGITS_SQUARED[number % 100000]
												number //= 100000

						return sum_of_digits_squared


# There are 2 Chains made,
# One ends with 89 with the chain member 58 being the one which when declared first,
# there will be the least number of iterations for all the members to be checked.

# The other one ends with 1 and has only one element 1.

# So 58 and 1 are chosen to be declared at the starting.

# Changed dictionary to an array to quicken the solution
_lowercase :  list[bool | None]    							=       [None] * 1_0_0_0_0_0_0_0
_lowercase :  List[str]    							=       True
_lowercase :  Optional[int]    							=       False
def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: int							):



						"""simple docstring"""





						if CHAINS[number - 1] is not None:
												return CHAINS[number - 1]  # type: ignore

						lowercase_	:     Tuple													=       chain(next_number(__SCREAMING_SNAKE_CASE							)							)
						lowercase_	:     Union[str, Any]													=       number_chain

						while number < 10000000:
												lowercase_	:     int													=       number_chain
												number *= 10

						return number_chain
def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: int = 10000000							):



						"""simple docstring"""





						for i in range(1      ,      __SCREAMING_SNAKE_CASE							):
												if CHAINS[i] is None:
																		chain(i + 1							)

						return CHAINS[:number].count(__SCREAMING_SNAKE_CASE							)


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							print(f"""{solution() = }""")



