
'''simple docstring'''
import shutil
import tempfile
import unittest
from unittest.mock import patch

from transformers import (
    DefaultFlowCallback,
    IntervalStrategy,
    PrinterCallback,
    ProgressCallback,
    Trainer,
    TrainerCallback,
    TrainingArguments,
    is_torch_available,
)
from transformers.testing_utils import require_torch


if is_torch_available():
				from transformers.trainer import DEFAULT_CALLBACKS

				from .test_trainer import RegressionDataset, RegressionModelConfig, RegressionPreTrainedModel


class       _lowerCAmelCase   (   __snake_case				):







							'''simple docstring'''

							def __init__(self  )					->       List[str]:
														_snake_case       =  []

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       str:
														self.events.append("""on_init_end"""  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       Union[str, Any]:
														self.events.append("""on_train_begin"""  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       int:
														self.events.append("""on_train_end"""  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       int:
														self.events.append("""on_epoch_begin"""  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       Union[str, Any]:
														self.events.append("""on_epoch_end"""  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       int:
														self.events.append("""on_step_begin"""  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       Dict:
														self.events.append("""on_step_end"""  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       str:
														self.events.append("""on_evaluate"""  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       Dict:
														self.events.append("""on_predict"""  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       Tuple:
														self.events.append("""on_save"""  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       List[str]:
														self.events.append("""on_log"""  )





							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  **UpperCAmelCase  )					->       Dict:
														self.events.append("""on_prediction_step"""  )


@require_torch
class       _lowerCAmelCase   (   unittest.TestCase				):







							'''simple docstring'''

							def 	lowercase							(self  )					->       Optional[int]:
														_snake_case       =  tempfile.mkdtemp()

							def 	lowercase							(self  )					->       List[str]:
														shutil.rmtree(self.output_dir  )

							def 	lowercase							(self  ,  UpperCAmelCase=0  ,  UpperCAmelCase=0  ,  UpperCAmelCase=64  ,  UpperCAmelCase=64  ,  UpperCAmelCase=None  ,  UpperCAmelCase=False  ,  **UpperCAmelCase  )					->       List[str]:
														# disable_tqdm in TrainingArguments has a flaky default since it depends on the level of logging. We make sure
														# its set to False since the tests later on depend on its value.
														_snake_case       =  RegressionDataset(length=UpperCAmelCase  )
														_snake_case       =  RegressionDataset(length=UpperCAmelCase  )
														_snake_case       =  RegressionModelConfig(a=UpperCAmelCase  ,  b=UpperCAmelCase  )
														_snake_case       =  RegressionPreTrainedModel(UpperCAmelCase  )

														_snake_case       =  TrainingArguments(self.output_dir  ,  disable_tqdm=UpperCAmelCase  ,  report_to=[]  ,  **UpperCAmelCase  )
														return Trainer(
														    UpperCAmelCase  ,  UpperCAmelCase  ,  train_dataset=UpperCAmelCase  ,  eval_dataset=UpperCAmelCase  ,  callbacks=UpperCAmelCase  ,  )

							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  )					->       List[str]:
														self.assertEqual(len(UpperCAmelCase  )  ,  len(UpperCAmelCase  )  )

														# Order doesn't matter
														_snake_case       =  sorted(UpperCAmelCase  ,  key=lambda UpperCAmelCase  : cb.__name__ if isinstance(UpperCAmelCase  ,  UpperCAmelCase  ) else cb.__class__.__name__  )
														_snake_case       =  sorted(UpperCAmelCase  ,  key=lambda UpperCAmelCase  : cb.__name__ if isinstance(UpperCAmelCase  ,  UpperCAmelCase  ) else cb.__class__.__name__  )

														for cba, cba in zip(UpperCAmelCase  ,  UpperCAmelCase  ):
																					if isinstance(UpperCAmelCase  ,  UpperCAmelCase  ) and isinstance(UpperCAmelCase  ,  UpperCAmelCase  ):
																												self.assertEqual(UpperCAmelCase  ,  UpperCAmelCase  )
																					elif isinstance(UpperCAmelCase  ,  UpperCAmelCase  ) and not isinstance(UpperCAmelCase  ,  UpperCAmelCase  ):
																												self.assertEqual(UpperCAmelCase  ,  cba.__class__  )
																					elif not isinstance(UpperCAmelCase  ,  UpperCAmelCase  ) and isinstance(UpperCAmelCase  ,  UpperCAmelCase  ):
																												self.assertEqual(cba.__class__  ,  UpperCAmelCase  )
																					else:
																												self.assertEqual(UpperCAmelCase  ,  UpperCAmelCase  )

							def 	lowercase							(self  ,  UpperCAmelCase  )					->       str:
														_snake_case       =  ["""on_init_end""", """on_train_begin"""]
														_snake_case       =  0
														_snake_case       =  len(trainer.get_eval_dataloader()  )
														_snake_case       =  ["""on_prediction_step"""] * len(trainer.get_eval_dataloader()  ) + ["""on_log""", """on_evaluate"""]
														for _ in range(trainer.state.num_train_epochs  ):
																					expected_events.append("""on_epoch_begin"""  )
																					for _ in range(UpperCAmelCase  ):
																												step += 1
																												expected_events += ["on_step_begin", "on_step_end"]
																												if step % trainer.args.logging_steps == 0:
																																			expected_events.append("""on_log"""  )
																												if trainer.args.evaluation_strategy == IntervalStrategy.STEPS and step % trainer.args.eval_steps == 0:
																																			expected_events += evaluation_events.copy()
																												if step % trainer.args.save_steps == 0:
																																			expected_events.append("""on_save"""  )
																					expected_events.append("""on_epoch_end"""  )
																					if trainer.args.evaluation_strategy == IntervalStrategy.EPOCH:
																												expected_events += evaluation_events.copy()
														expected_events += ["on_log", "on_train_end"]
														return expected_events

							def 	lowercase							(self  )					->       Any:
														_snake_case       =  self.get_trainer()
														_snake_case       =  DEFAULT_CALLBACKS.copy() + [ProgressCallback]
														self.check_callbacks_equality(trainer.callback_handler.callbacks  ,  UpperCAmelCase  )

														# Callbacks passed at init are added to the default callbacks
														_snake_case       =  self.get_trainer(callbacks=[MyTestTrainerCallback]  )
														expected_callbacks.append(UpperCAmelCase  )
														self.check_callbacks_equality(trainer.callback_handler.callbacks  ,  UpperCAmelCase  )

														# TrainingArguments.disable_tqdm controls if use ProgressCallback or PrinterCallback
														_snake_case       =  self.get_trainer(disable_tqdm=UpperCAmelCase  )
														_snake_case       =  DEFAULT_CALLBACKS.copy() + [PrinterCallback]
														self.check_callbacks_equality(trainer.callback_handler.callbacks  ,  UpperCAmelCase  )

							def 	lowercase							(self  )					->       Dict:
														_snake_case       =  DEFAULT_CALLBACKS.copy() + [ProgressCallback]
														_snake_case       =  self.get_trainer()

														# We can add, pop, or remove by class name
														trainer.remove_callback(UpperCAmelCase  )
														expected_callbacks.remove(UpperCAmelCase  )
														self.check_callbacks_equality(trainer.callback_handler.callbacks  ,  UpperCAmelCase  )

														_snake_case       =  self.get_trainer()
														_snake_case       =  trainer.pop_callback(UpperCAmelCase  )
														self.assertEqual(cb.__class__  ,  UpperCAmelCase  )
														self.check_callbacks_equality(trainer.callback_handler.callbacks  ,  UpperCAmelCase  )

														trainer.add_callback(UpperCAmelCase  )
														expected_callbacks.insert(0  ,  UpperCAmelCase  )
														self.check_callbacks_equality(trainer.callback_handler.callbacks  ,  UpperCAmelCase  )

														# We can also add, pop, or remove by instance
														_snake_case       =  self.get_trainer()
														_snake_case       =  trainer.callback_handler.callbacks[0]
														trainer.remove_callback(UpperCAmelCase  )
														expected_callbacks.remove(UpperCAmelCase  )
														self.check_callbacks_equality(trainer.callback_handler.callbacks  ,  UpperCAmelCase  )

														_snake_case       =  self.get_trainer()
														_snake_case       =  trainer.callback_handler.callbacks[0]
														_snake_case       =  trainer.pop_callback(UpperCAmelCase  )
														self.assertEqual(UpperCAmelCase  ,  UpperCAmelCase  )
														self.check_callbacks_equality(trainer.callback_handler.callbacks  ,  UpperCAmelCase  )

														trainer.add_callback(UpperCAmelCase  )
														expected_callbacks.insert(0  ,  UpperCAmelCase  )
														self.check_callbacks_equality(trainer.callback_handler.callbacks  ,  UpperCAmelCase  )





							def 	lowercase							(self  )					->       Dict:
														import warnings

														# XXX: for now ignore scatter_gather warnings in this test since it's not relevant to what's being tested
														warnings.simplefilter(action="""ignore"""  ,  category=UpperCAmelCase  )

														_snake_case       =  self.get_trainer(callbacks=[MyTestTrainerCallback]  )
														trainer.train()
														_snake_case       =  trainer.callback_handler.callbacks[-2].events
														self.assertEqual(UpperCAmelCase  ,  self.get_expected_events(UpperCAmelCase  )  )

														# Independent log/save/eval
														_snake_case       =  self.get_trainer(callbacks=[MyTestTrainerCallback]  ,  logging_steps=5  )
														trainer.train()
														_snake_case       =  trainer.callback_handler.callbacks[-2].events
														self.assertEqual(UpperCAmelCase  ,  self.get_expected_events(UpperCAmelCase  )  )

														_snake_case       =  self.get_trainer(callbacks=[MyTestTrainerCallback]  ,  save_steps=5  )
														trainer.train()
														_snake_case       =  trainer.callback_handler.callbacks[-2].events
														self.assertEqual(UpperCAmelCase  ,  self.get_expected_events(UpperCAmelCase  )  )

														_snake_case       =  self.get_trainer(callbacks=[MyTestTrainerCallback]  ,  eval_steps=5  ,  evaluation_strategy="""steps"""  )
														trainer.train()
														_snake_case       =  trainer.callback_handler.callbacks[-2].events
														self.assertEqual(UpperCAmelCase  ,  self.get_expected_events(UpperCAmelCase  )  )

														_snake_case       =  self.get_trainer(callbacks=[MyTestTrainerCallback]  ,  evaluation_strategy="""epoch"""  )
														trainer.train()
														_snake_case       =  trainer.callback_handler.callbacks[-2].events
														self.assertEqual(UpperCAmelCase  ,  self.get_expected_events(UpperCAmelCase  )  )

														# A bit of everything
														_snake_case       =  self.get_trainer(
														    callbacks=[MyTestTrainerCallback]  ,  logging_steps=3  ,  save_steps=10  ,  eval_steps=5  ,  evaluation_strategy="""steps"""  ,  )
														trainer.train()
														_snake_case       =  trainer.callback_handler.callbacks[-2].events
														self.assertEqual(UpperCAmelCase  ,  self.get_expected_events(UpperCAmelCase  )  )

														# warning should be emitted for duplicated callbacks
														with patch("""transformers.trainer_callback.logger.warning"""  ) as warn_mock:
																					_snake_case       =  self.get_trainer(
																					    callbacks=[MyTestTrainerCallback, MyTestTrainerCallback]  ,  )
																					assert str(UpperCAmelCase  ) in warn_mock.call_args[0][0]

'''simple docstring'''
from __future__ import annotations

import typing
from collections import Counter






def  __SCREAMING_SNAKE_CASE				(  _SCREAMING_SNAKE_CASE				):
							_snake_case       =  Counter()
							for base in range(1							, max_perimeter + 1				):
														for perpendicular in range(_SCREAMING_SNAKE_CASE							, max_perimeter + 1				):
																					_snake_case       =  (base * base + perpendicular * perpendicular) ** 0.5
																					if hypotenuse == int(_SCREAMING_SNAKE_CASE				):
																												_snake_case       =  int(base + perpendicular + hypotenuse				)
																												if perimeter > max_perimeter:
																																			continue
																												triplets[perimeter] += 1
							return triplets






def  __SCREAMING_SNAKE_CASE				(  _SCREAMING_SNAKE_CASE = 1000				):
							_snake_case       =  pythagorean_triple(_SCREAMING_SNAKE_CASE				)
							return triplets.most_common(1				)[0][0]


if __name__ == "__main__":
				print(f'''Perimeter {solution()} has maximum solutions''')