



"""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      __UpperCAmelCase      (    __lowerCamelCase	)							->      Any:
		if is_torch_version('''<'''						,     '''2.0.0'''	) or not hasattr(__lowerCamelCase						,     '''_dynamo'''	):
				return False
		return isinstance(__lowerCamelCase						,     torch._dynamo.eval_frame.OptimizedModule	)



def      __UpperCAmelCase      (    __lowerCamelCase						,     __lowerCamelCase = True	)							->      Dict:
		lowercase__   :    Optional[Any]				=			(torch.nn.parallel.DistributedDataParallel, torch.nn.DataParallel)

		lowercase__   :    Any				=			is_compiled_module(__lowerCamelCase	)
		if is_compiled:
				lowercase__   :    Dict				=			model
				lowercase__   :    Tuple				=			model._orig_mod

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

		while isinstance(__lowerCamelCase						,     __lowerCamelCase	):
				lowercase__   :    int				=			model.module

		if not keep_fpaa_wrapper:
				lowercase__   :    str				=			getattr(__lowerCamelCase						,     '''forward'''	)
				lowercase__   :    List[str]				=			model.__dict__.pop('''_original_forward'''						,     __lowerCamelCase	)
				if original_forward is not None:
						while hasattr(__lowerCamelCase						,     '''__wrapped__'''	):
								lowercase__   :    List[Any]				=			forward.__wrapped__
								if forward == original_forward:
										break
						lowercase__   :    Optional[Any]				=			forward
				if getattr(__lowerCamelCase						,     '''_converted_to_transformer_engine'''						,     __lowerCamelCase	):
						convert_model(__lowerCamelCase						,     to_transformer_engine=__lowerCamelCase	)

		if is_compiled:
				lowercase__   :    Optional[Any]				=			model
				lowercase__   :    Tuple				=			compiled_model

		return model



def      __UpperCAmelCase      (    )							->      str:
		PartialState().wait_for_everyone()



def      __UpperCAmelCase      (    __lowerCamelCase						,     __lowerCamelCase	)							->      Union[str, Any]:
		if PartialState().distributed_type == DistributedType.TPU:
				xm.save(__lowerCamelCase						,     __lowerCamelCase	)
		elif PartialState().local_process_index == 0:
				torch.save(__lowerCamelCase						,     __lowerCamelCase	)



@contextmanager
def      __UpperCAmelCase      (    **__lowerCamelCase	)							->      Optional[Any]:
		for key, value in kwargs.items():
				lowercase__   :    Tuple				=			str(__lowerCamelCase	)

		yield

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



def      __UpperCAmelCase      (    __lowerCamelCase	)							->      List[Any]:
		if not hasattr(__lowerCamelCase						,     '''__qualname__'''	) and not hasattr(__lowerCamelCase						,     '''__name__'''	):
				lowercase__   :    Tuple				=			getattr(__lowerCamelCase						,     '''__class__'''						,     __lowerCamelCase	)
		if hasattr(__lowerCamelCase						,     '''__qualname__'''	):
				return obj.__qualname__
		if hasattr(__lowerCamelCase						,     '''__name__'''	):
				return obj.__name__
		return str(__lowerCamelCase	)



def      __UpperCAmelCase      (    __lowerCamelCase						,     __lowerCamelCase	)							->      str:
		for key, value in source.items():
				if isinstance(__lowerCamelCase						,     __lowerCamelCase	):
						lowercase__   :    List[str]				=			destination.setdefault(__lowerCamelCase						,     {}	)
						merge_dicts(__lowerCamelCase						,     __lowerCamelCase	)
				else:
						lowercase__   :    Any				=			value

		return destination





def      __UpperCAmelCase      (    __lowerCamelCase = None	)							->      bool:
		if port is None:
				lowercase__   :    Optional[Any]				=			2_95_00
		with socket.socket(socket.AF_INET						,     socket.SOCK_STREAM	) as s:
				return s.connect_ex(('''localhost''', port)	) == 0





"""simple docstring"""







def      __UpperCAmelCase      (    __lowerCamelCase = 50	)							->      int:
		lowercase__   :    int				=			[[0] * 3 for _ in range(length + 1	)]

		for row_length in range(length + 1	):
				for tile_length in range(2						,     5	):
						for tile_start in range(row_length - tile_length + 1	):
								different_colour_ways_number[row_length][tile_length - 2] += (
								    different_colour_ways_number[row_length - tile_start - tile_length][
								        tile_length - 2
								    ]
								    + 1
								)

		return sum(different_colour_ways_number[length]	)


if __name__ == "__main__":
							print(F'''{solution() = }''')
