

import inspect
import os
import unittest
from pathlib import Path

import torch

import accelerate
from accelerate.test_utils import execute_subprocess_async
from accelerate.test_utils.testing import run_command



class   __lowercase    (			unittest.TestCase     ):




			"""simple docstring"""







			_UpperCAmelCase       :							List[str]      							=					inspect.getfile(accelerate.test_utils     )
			_UpperCAmelCase       :							Any      							=					os.path.sep.join(mod_file.split(os.path.sep     )[:-1] + ['''scripts''', '''test_cli.py''']     )

			_UpperCAmelCase       :							List[Any]      							=					['''accelerate''', '''launch''']
			_UpperCAmelCase       :							Dict      							=					Path.home() / '''.cache/huggingface/accelerate'''
			_UpperCAmelCase       :							str      							=					'''default_config.yaml'''
			_UpperCAmelCase       :							Optional[int]      							=					config_folder / config_file
			_UpperCAmelCase       :							Optional[int]      							=					config_folder / '''_default_config.yaml'''

			_UpperCAmelCase       :							Optional[int]      							=					Path('''tests/test_configs'''     )



			@classmethod
			def 	_SCREAMING_SNAKE_CASE      (			cls  :					List[str]):
									if cls.config_path.is_file():
															cls.config_path.rename(cls.changed_path)



			@classmethod
			def 	_SCREAMING_SNAKE_CASE      (			cls  :					Any):
									if cls.changed_path.is_file():
															cls.changed_path.rename(cls.config_path)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Optional[Any]):
									SCREAMING_SNAKE_CASE_:			int  		=	self.base_cmd
									if torch.cuda.is_available() and (torch.cuda.device_count() > 1):
															cmd += ["--multi_gpu"]
									execute_subprocess_async(cmd + [self.test_file_path]       ,						env=os.environ.copy())



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Optional[int]):
									for config in sorted(self.test_config_path.glob("**/*.yaml")):
															with self.subTest(config_file=lowerCAmelCase__):
																					execute_subprocess_async(
																					    self.base_cmd + ["--config_file", str(lowerCAmelCase__), self.test_file_path]       ,						env=os.environ.copy())




			def 	_SCREAMING_SNAKE_CASE      (			self  :					Union[str, Any]):
									execute_subprocess_async(["accelerate", "test"]       ,						env=os.environ.copy())







class   __lowercase    (			unittest.TestCase     ):




			"""simple docstring"""







			_UpperCAmelCase       :							Any      							=					'''test-tpu'''
			_UpperCAmelCase       :							List[Any]      							=					'''us-central1-a'''
			_UpperCAmelCase       :							Tuple      							=					'''ls'''
			_UpperCAmelCase       :							int      							=					['''accelerate''', '''tpu-config''']
			_UpperCAmelCase       :							str      							=					'''cd /usr/share'''
			_UpperCAmelCase       :							Any      							=					'''tests/test_samples/test_command_file.sh'''
			_UpperCAmelCase       :							List[Any]      							=					'''Running gcloud compute tpus tpu-vm ssh'''



			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[str]):
									SCREAMING_SNAKE_CASE_:			Tuple  		=	run_command(
									    self.cmd
									    + ["--command", self.command, "--tpu_zone", self.tpu_zone, "--tpu_name", self.tpu_name, "--debug"]       ,						return_stdout=lowerCAmelCase__       ,						)
									self.assertIn(
									    F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"       ,						lowerCAmelCase__       ,						)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[Any]):
									SCREAMING_SNAKE_CASE_:			List[str]  		=	run_command(
									    self.cmd
									    + [
									        "--config_file",
									        "tests/test_configs/0_12_0.yaml",
									        "--command",
									        self.command,
									        "--tpu_zone",
									        self.tpu_zone,
									        "--tpu_name",
									        self.tpu_name,
									        "--debug",
									    ]       ,						return_stdout=lowerCAmelCase__       ,						)
									self.assertIn(
									    F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"       ,						lowerCAmelCase__       ,						)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[str]):
									SCREAMING_SNAKE_CASE_:			int  		=	run_command(
									    self.cmd + ["--config_file", "tests/test_configs/latest.yaml", "--debug"]       ,						return_stdout=lowerCAmelCase__)
									self.assertIn(
									    F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; echo \"hello world\"; echo \"this is a second command\" --worker all"       ,						lowerCAmelCase__       ,						)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Optional[int]):
									SCREAMING_SNAKE_CASE_:			Tuple  		=	run_command(
									    self.cmd + ["--config_file", "tests/test_configs/latest.yaml", "--command", self.command, "--debug"]       ,						return_stdout=lowerCAmelCase__       ,						)
									self.assertIn(
									    F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls --worker all"       ,						lowerCAmelCase__       ,						)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					List[Any]):
									SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	run_command(
									    self.cmd
									    + [
									        "--config_file",
									        "tests/test_configs/latest.yaml",
									        "--command",
									        self.command,
									        "--command",
									        "echo \"Hello World\"",
									        "--debug",
									    ]       ,						return_stdout=lowerCAmelCase__       ,						)
									self.assertIn(
									    F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; ls; echo \"Hello World\" --worker all"       ,						lowerCAmelCase__       ,						)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Dict):
									SCREAMING_SNAKE_CASE_:			Optional[Any]  		=	run_command(
									    self.cmd
									    + ["--config_file", "tests/test_configs/latest.yaml", "--command_file", self.command_file, "--debug"]       ,						return_stdout=lowerCAmelCase__       ,						)
									self.assertIn(
									    F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; echo \"hello world\"; echo \"this is a second command\" --worker all"       ,						lowerCAmelCase__       ,						)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					int):
									SCREAMING_SNAKE_CASE_:			List[Any]  		=	run_command(
									    self.cmd
									    + [
									        "--config_file",
									        "tests/test_configs/0_12_0.yaml",
									        "--command_file",
									        self.command_file,
									        "--tpu_zone",
									        self.tpu_zone,
									        "--tpu_name",
									        self.tpu_name,
									        "--debug",
									    ]       ,						return_stdout=lowerCAmelCase__       ,						)
									self.assertIn(
									    F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; echo \"hello world\"; echo \"this is a second command\" --worker all"       ,						lowerCAmelCase__       ,						)



			def 	_SCREAMING_SNAKE_CASE      (			self  :					Tuple):
									SCREAMING_SNAKE_CASE_:			int  		=	run_command(
									    self.cmd + ["--config_file", "tests/test_configs/latest.yaml", "--install_accelerate", "--debug"]       ,						return_stdout=lowerCAmelCase__       ,						)
									self.assertIn(
									    F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; pip install accelerate -U; echo \"hello world\"; echo \"this is a second command\" --worker all"       ,						lowerCAmelCase__       ,						)




			def 	_SCREAMING_SNAKE_CASE      (			self  :					Union[str, Any]):
									SCREAMING_SNAKE_CASE_:			int  		=	run_command(
									    self.cmd
									    + [
									        "--config_file",
									        "tests/test_configs/latest.yaml",
									        "--install_accelerate",
									        "--accelerate_version",
									        "12.0.0",
									        "--debug",
									    ]       ,						return_stdout=lowerCAmelCase__       ,						)
									self.assertIn(
									    F"{self.gcloud} test-tpu --zone us-central1-a --command {self.base_output}; pip install accelerate==12.0.0; echo \"hello world\"; echo \"this is a second command\" --worker all"       ,						lowerCAmelCase__       ,						)









import os

# Precomputes a list of the 100 first triangular numbers
lowerCAmelCase							:  Optional[int]            =						[int(0.5 * n * (n + 1)) for n in range(1, 101)]







def       A_				(   ):
						SCREAMING_SNAKE_CASE_:			List[str]  		=	os.path.dirname(os.path.realpath(_UpperCAmelCase   )   )
						SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	os.path.join(_UpperCAmelCase    ,     "words.txt"   )

						SCREAMING_SNAKE_CASE_:			Dict  		=	""
						with open(_UpperCAmelCase   ) as f:
												SCREAMING_SNAKE_CASE_:			int  		=	f.readline()

						SCREAMING_SNAKE_CASE_:			Optional[int]  		=	[word.strip("\""   ) for word in words.strip("\r\n"   ).split(","   )]
						SCREAMING_SNAKE_CASE_:			List[Any]  		=	[
						    word
						    for word in [sum(ord(_UpperCAmelCase   ) - 64 for x in word   ) for word in words]
						    if word in TRIANGULAR_NUMBERS
						]
						return len(_UpperCAmelCase   )


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






