



"""simple docstring"""






import os
import socket
from contextlib import contextmanager

import torch

from ..commands.config.default import write_basic_config  # noqa: F401
from ..state import PartialState
from .dataclasses import DistributedType
from .imports import is_deepspeed_available, is_tpu_available
from .transformer_engine import convert_model
from .versions import is_torch_version


if is_deepspeed_available():
   from deepspeed import DeepSpeedEngine

if is_tpu_available(check_device=False):
   import torch_xla.core.xla_model as xm






def 			snake_case_    ( A_   :						List[Any]		):


       '''simple docstring'''





       if is_torch_version('''<''',							'''2.0.0'''		) or not hasattr(A_,							'''_dynamo'''		):
              return False
       return isinstance(A_,							torch._dynamo.eval_frame.OptimizedModule		)






def 			snake_case_    ( A_   :						List[str],							A_   :						bool = True		):


       '''simple docstring'''





       _lowerCamelCase		:							Tuple            =					(torch.nn.parallel.DistributedDataParallel, torch.nn.DataParallel)

       _lowerCamelCase		:							Any            =					is_compiled_module(A_		)
       if is_compiled:
              _lowerCamelCase		:							Dict            =					model
              _lowerCamelCase		:							Any            =					model._orig_mod

       if is_deepspeed_available():
              options += (DeepSpeedEngine,)

       while isinstance(A_,							A_		):
              _lowerCamelCase		:							List[Any]            =					model.module

       if not keep_fpaa_wrapper:
              _lowerCamelCase		:							int            =					getattr(A_,							'''forward'''		)
              _lowerCamelCase		:							int            =					model.__dict__.pop('''_original_forward''',							A_		)
              if original_forward is not None:
                     while hasattr(A_,							'''__wrapped__'''		):
                            _lowerCamelCase		:							Union[str, Any]            =					forward.__wrapped__
                            if forward == original_forward:
                                   break
                     _lowerCamelCase		:							int            =					forward
              if getattr(A_,							'''_converted_to_transformer_engine''',							A_		):
                     convert_model(A_,							to_transformer_engine=A_		)

       if is_compiled:
              _lowerCamelCase		:							Dict            =					model
              _lowerCamelCase		:							int            =					compiled_model

       return model






def 			snake_case_    ( ):


       '''simple docstring'''





       PartialState().wait_for_everyone()






def 			snake_case_    ( A_   :						Optional[int],							A_   :						str		):


       '''simple docstring'''





       if PartialState().distributed_type == DistributedType.TPU:
              xm.save(A_,							A_		)
       elif PartialState().local_process_index == 0:
              torch.save(A_,							A_		)






@contextmanager
def 			snake_case_    ( **A_   :						Any		):


       '''simple docstring'''





       for key, value in kwargs.items():
              _lowerCamelCase		:							Union[str, Any]            =					str(A_		)

       yield

       for key in kwargs:
              if key.upper() in os.environ:
                     del os.environ[key.upper()]






def 			snake_case_    ( A_   :						Any		):


       '''simple docstring'''





       if not hasattr(A_,							'''__qualname__'''		) and not hasattr(A_,							'''__name__'''		):
              _lowerCamelCase		:							Union[str, Any]            =					getattr(A_,							'''__class__''',							A_		)
       if hasattr(A_,							'''__qualname__'''		):
              return obj.__qualname__
       if hasattr(A_,							'''__name__'''		):
              return obj.__name__
       return str(A_		)






def 			snake_case_    ( A_   :						Any,							A_   :						Dict		):


       '''simple docstring'''





       for key, value in source.items():
              if isinstance(A_,							A_		):
                     _lowerCamelCase		:							Optional[Any]            =					destination.setdefault(A_,							{}		)
                     merge_dicts(A_,							A_		)
              else:
                     _lowerCamelCase		:							Any            =					value

       return destination







def 			snake_case_    ( A_   :						int = None		):


       '''simple docstring'''





       if port is None:
              _lowerCamelCase		:							Optional[int]            =					2_95_00
       with socket.socket(socket.AF_INET,							socket.SOCK_STREAM		) as s:
              return s.connect_ex(('''localhost''', port)		) == 0










import os

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





def    __lowerCAmelCase   (    ):
     __lowerCAmelCase             =       os.path.dirname(os.path.realpath(__snake_case							)							)
     __lowerCAmelCase             =       os.path.join(__snake_case       ,			"words.txt"							)

     __lowerCAmelCase             =       ""
     with open(__snake_case							) as f:
          __lowerCAmelCase             =       f.readline()

     __lowerCAmelCase             =       [word.strip("\""							) for word in words.strip("\r\n"							).split(","							)]
     __lowerCAmelCase             =       [
         word
         for word in [sum(ord(__snake_case							) - 64 for x in word							) for word in words]
         if word in TRIANGULAR_NUMBERS
     ]
     return len(__snake_case							)


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






