



"""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        __A       (	A_    ):







		'''simple docstring'''





		def __init__(	self						:  Dict						)					->		Tuple:






				"""simple docstring"""



				lowercase__   :    Optional[int]				=			[]







		def 					UpperCAmelCase    (	self						:  Optional[int]			,_snake_case						:  Optional[Any]			,_snake_case						:  int			,_snake_case						:  List[str]			,**_snake_case						:  int						)					->		Tuple:






				"""simple docstring"""



				self.events.append('''on_init_end'''						)







		def 					UpperCAmelCase    (	self						:  Union[str, Any]			,_snake_case						:  List[str]			,_snake_case						:  Dict			,_snake_case						:  Tuple			,**_snake_case						:  str						)					->		Optional[Any]:






				"""simple docstring"""



				self.events.append('''on_train_begin'''						)







		def 					UpperCAmelCase    (	self						:  int			,_snake_case						:  Optional[int]			,_snake_case						:  Optional[Any]			,_snake_case						:  int			,**_snake_case						:  str						)					->		List[str]:






				"""simple docstring"""



				self.events.append('''on_train_end'''						)







		def 					UpperCAmelCase    (	self						:  List[Any]			,_snake_case						:  Optional[Any]			,_snake_case						:  Optional[int]			,_snake_case						:  Union[str, Any]			,**_snake_case						:  Optional[int]						)					->		List[str]:






				"""simple docstring"""



				self.events.append('''on_epoch_begin'''						)







		def 					UpperCAmelCase    (	self						:  Optional[Any]			,_snake_case						:  List[Any]			,_snake_case						:  Tuple			,_snake_case						:  Union[str, Any]			,**_snake_case						:  Tuple						)					->		List[Any]:






				"""simple docstring"""



				self.events.append('''on_epoch_end'''						)







		def 					UpperCAmelCase    (	self						:  Tuple			,_snake_case						:  List[Any]			,_snake_case						:  Optional[int]			,_snake_case						:  Dict			,**_snake_case						:  Optional[int]						)					->		Dict:






				"""simple docstring"""



				self.events.append('''on_step_begin'''						)







		def 					UpperCAmelCase    (	self						:  Optional[Any]			,_snake_case						:  str			,_snake_case						:  int			,_snake_case						:  List[str]			,**_snake_case						:  List[Any]						)					->		int:






				"""simple docstring"""



				self.events.append('''on_step_end'''						)







		def 					UpperCAmelCase    (	self						:  Any			,_snake_case						:  Optional[int]			,_snake_case						:  Optional[int]			,_snake_case						:  Optional[Any]			,**_snake_case						:  List[str]						)					->		Optional[int]:






				"""simple docstring"""



				self.events.append('''on_evaluate'''						)







		def 					UpperCAmelCase    (	self						:  List[str]			,_snake_case						:  Dict			,_snake_case						:  Dict			,_snake_case						:  int			,**_snake_case						:  Union[str, Any]						)					->		List[Any]:






				"""simple docstring"""



				self.events.append('''on_predict'''						)







		def 					UpperCAmelCase    (	self						:  Optional[int]			,_snake_case						:  Optional[Any]			,_snake_case						:  List[str]			,_snake_case						:  List[str]			,**_snake_case						:  Optional[int]						)					->		Dict:






				"""simple docstring"""



				self.events.append('''on_save'''						)







		def 					UpperCAmelCase    (	self						:  int			,_snake_case						:  Union[str, Any]			,_snake_case						:  int			,_snake_case						:  List[Any]			,**_snake_case						:  Optional[Any]						)					->		List[Any]:






				"""simple docstring"""



				self.events.append('''on_log'''						)







		def 					UpperCAmelCase    (	self						:  List[str]			,_snake_case						:  List[Any]			,_snake_case						:  Tuple			,_snake_case						:  Dict			,**_snake_case						:  int						)					->		Dict:






				"""simple docstring"""



				self.events.append('''on_prediction_step'''						)





@require_torch
class        __A       (	unittest.TestCase    ):







		'''simple docstring'''





		def 					UpperCAmelCase    (	self						:  Any						)					->		str:






				"""simple docstring"""



				lowercase__   :    List[str]				=			tempfile.mkdtemp()







		def 					UpperCAmelCase    (	self						:  Optional[int]						)					->		int:






				"""simple docstring"""



				shutil.rmtree(self.output_dir						)







		def 					UpperCAmelCase    (	self						:  Dict			,_snake_case						:  List[str]=0			,_snake_case						:  Union[str, Any]=0			,_snake_case						:  Tuple=64			,_snake_case						:  Any=64			,_snake_case						:  List[Any]=None			,_snake_case						:  Any=False			,**_snake_case						:  Optional[Any]						)					->		Union[str, Any]:






				"""simple docstring"""



				lowercase__   :    Any				=			RegressionDataset(length=_snake_case						)
				lowercase__   :    List[Any]				=			RegressionDataset(length=_snake_case						)
				lowercase__   :    Tuple				=			RegressionModelConfig(a=_snake_case			,b=_snake_case						)
				lowercase__   :    Dict				=			RegressionPreTrainedModel(_snake_case						)

				lowercase__   :    Optional[Any]				=			TrainingArguments(self.output_dir			,disable_tqdm=_snake_case			,report_to=[]			,**_snake_case						)
				return Trainer(
				    _snake_case			,_snake_case			,train_dataset=_snake_case			,eval_dataset=_snake_case			,callbacks=_snake_case			,)







		def 					UpperCAmelCase    (	self						:  Union[str, Any]			,_snake_case						:  Optional[int]			,_snake_case						:  Dict						)					->		List[Any]:






				"""simple docstring"""



				self.assertEqual(len(_snake_case						)			,len(_snake_case						)						)

				# Order doesn't matter
				lowercase__   :    str				=			sorted(_snake_case			,key=lambda _snake_case						: cb.__name__ if isinstance(_snake_case			,_snake_case						) else cb.__class__.__name__						)
				lowercase__   :    Optional[Any]				=			sorted(_snake_case			,key=lambda _snake_case						: cb.__name__ if isinstance(_snake_case			,_snake_case						) else cb.__class__.__name__						)

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







		def 					UpperCAmelCase    (	self						:  Union[str, Any]			,_snake_case						:  Dict						)					->		List[str]:






				"""simple docstring"""



				lowercase__   :    Optional[int]				=			['''on_init_end''', '''on_train_begin''']
				lowercase__   :    List[str]				=			0
				lowercase__   :    Dict				=			len(trainer.get_eval_dataloader()						)
				lowercase__   :    Any				=			['''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(_snake_case						):
								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 					UpperCAmelCase    (	self						:  Tuple						)					->		List[str]:






				"""simple docstring"""



				lowercase__   :    Any				=			self.get_trainer()
				lowercase__   :    List[Any]				=			DEFAULT_CALLBACKS.copy() + [ProgressCallback]
				self.check_callbacks_equality(trainer.callback_handler.callbacks			,_snake_case						)

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

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







		def 					UpperCAmelCase    (	self						:  Tuple						)					->		Optional[int]:






				"""simple docstring"""



				lowercase__   :    Optional[int]				=			DEFAULT_CALLBACKS.copy() + [ProgressCallback]
				lowercase__   :    List[str]				=			self.get_trainer()

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

				lowercase__   :    Optional[Any]				=			self.get_trainer()
				lowercase__   :    int				=			trainer.pop_callback(_snake_case						)
				self.assertEqual(cb.__class__			,_snake_case						)
				self.check_callbacks_equality(trainer.callback_handler.callbacks			,_snake_case						)

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

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

				lowercase__   :    str				=			self.get_trainer()
				lowercase__   :    Optional[int]				=			trainer.callback_handler.callbacks[0]
				lowercase__   :    Tuple				=			trainer.pop_callback(_snake_case						)
				self.assertEqual(_snake_case			,_snake_case						)
				self.check_callbacks_equality(trainer.callback_handler.callbacks			,_snake_case						)

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







		def 					UpperCAmelCase    (	self						:  List[str]						)					->		Union[str, Any]:






				"""simple docstring"""



				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=_snake_case						)

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

				# Independent log/save/eval
				lowercase__   :    Union[str, Any]				=			self.get_trainer(callbacks=[MyTestTrainerCallback]			,logging_steps=5						)
				trainer.train()
				lowercase__   :    Optional[int]				=			trainer.callback_handler.callbacks[-2].events
				self.assertEqual(_snake_case			,self.get_expected_events(_snake_case						)						)

				lowercase__   :    str				=			self.get_trainer(callbacks=[MyTestTrainerCallback]			,save_steps=5						)
				trainer.train()
				lowercase__   :    Union[str, Any]				=			trainer.callback_handler.callbacks[-2].events
				self.assertEqual(_snake_case			,self.get_expected_events(_snake_case						)						)

				lowercase__   :    int				=			self.get_trainer(callbacks=[MyTestTrainerCallback]			,eval_steps=5			,evaluation_strategy='''steps'''						)
				trainer.train()
				lowercase__   :    Union[str, Any]				=			trainer.callback_handler.callbacks[-2].events
				self.assertEqual(_snake_case			,self.get_expected_events(_snake_case						)						)

				lowercase__   :    Dict				=			self.get_trainer(callbacks=[MyTestTrainerCallback]			,evaluation_strategy='''epoch'''						)
				trainer.train()
				lowercase__   :    Dict				=			trainer.callback_handler.callbacks[-2].events
				self.assertEqual(_snake_case			,self.get_expected_events(_snake_case						)						)

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

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





"""simple docstring"""







import os



def      __UpperCAmelCase      (    )							->      int:
		with open(os.path.dirname(__lowerCamelCase	) + '''/p022_names.txt'''	) as file:
				lowercase__   :    List[Any]				=			str(file.readlines()[0]	)
				lowercase__   :    Dict				=			names.replace('''"'''						,     ''''''	).split(''','''	)

		names.sort()

		lowercase__   :    int				=			0
		lowercase__   :    Optional[Any]				=			0

		for i, name in enumerate(__lowerCamelCase	):
				for letter in name:
						name_score += ord(__lowerCamelCase	) - 64

				total_score += (i + 1) * name_score
				lowercase__   :    List[str]				=			0
		return total_score


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