"""simple docstring"""







import inspect
import warnings

import torch

from .state import AcceleratorState, GradientState
from .utils import DistributedType, honor_type, is_tpu_available


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




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				int  ,       _SCREAMING_SNAKE_CASE				:				Any						)    ->     Any:







     '''simple docstring'''


     if isinstance(lowerCAmelCase_  ,       (list, tuple)						):
          return honor_type(lowerCAmelCase_  ,       (move_to_device(lowerCAmelCase_  ,       lowerCAmelCase_						) for t in state)						)
     elif isinstance(lowerCAmelCase_  ,       lowerCAmelCase_						):
          return type(lowerCAmelCase_						)({k: move_to_device(lowerCAmelCase_  ,       lowerCAmelCase_						) for k, v in state.items()}						)
     elif isinstance(lowerCAmelCase_  ,       torch.Tensor						):
          return state.to(lowerCAmelCase_						)
     return state






class 							__snake_case(					torch.optim.Optimizer	):


    '''simple docstring'''





    def __init__(  self					,       __lowerCamelCase					,       __lowerCamelCase=True					,       __lowerCamelCase=None	):




         '''simple docstring'''



         __A					:					Any								=		optimizer
         __A					:					Optional[int]								=		scaler
         __A					:					List[Any]								=		AcceleratorState()
         __A					:					Any								=		GradientState()
         __A					:					List[str]								=		device_placement
         __A					:					str								=		False
         __A					:					Union[str, Any]								=		None

         # Handle device placement
         if device_placement:
              __A					:					List[Any]								=		self.optimizer.state_dict()
              if self.accelerator_state.distributed_type == DistributedType.TPU:
                   xm.send_cpu_data_to_device(a_					,       self.accelerator_state.device	)
              else:
                   __A					:					Optional[int]								=		move_to_device(a_					,       self.accelerator_state.device	)
              self.optimizer.load_state_dict(a_	)
    @property
    def 						_a							(  self	):




         '''simple docstring'''



         return self.optimizer.state
    @state.setter
    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					Optional[int]								=		state
    @property
    def 						_a							(  self	):




         '''simple docstring'''



         return self.optimizer.param_groups
    @param_groups.setter
    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					int								=		param_groups
    @property
    def 						_a							(  self	):




         '''simple docstring'''



         return self.optimizer.defaults
    @defaults.setter
    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         __A					:					Optional[Any]								=		defaults
    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         self.optimizer.add_param_group(a_	)
    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         if self.accelerator_state.distributed_type == DistributedType.TPU and self.device_placement:
              xm.send_cpu_data_to_device(a_					,       self.accelerator_state.device	)
         self.optimizer.load_state_dict(a_	)
    def 						_a							(  self	):




         '''simple docstring'''



         return self.optimizer.state_dict()
    def 						_a							(  self					,       __lowerCamelCase=None	):




         '''simple docstring'''



         if self.gradient_state.sync_gradients:
              __A					:					List[Any]								=		"""set_to_none""" in inspect.signature(self.optimizer.zero_grad	).parameters
              if accept_arg:
                   if set_to_none is None:
                        __A					:					Tuple								=		False
                   self.optimizer.zero_grad(set_to_none=a_	)
              else:
                   if set_to_none is not None:
                        raise ValueError('`set_to_none` for Optimizer.zero_grad` is not supported by this optimizer.'	)
                   self.optimizer.zero_grad()
    def 						_a							(  self					,       __lowerCamelCase=None	):




         '''simple docstring'''



         if self.gradient_state.sync_gradients:
              if self.accelerator_state.distributed_type == DistributedType.TPU:
                   __A					:					str								=		{"""closure""": closure} if closure is not None else {}
                   xm.optimizer_step(self.optimizer					,       optimizer_args=a_	)
              elif self.scaler is not None:
                   __A					:					Tuple								=		False
                   if self._last_scale is None:
                        # `get_scale` is an async operation requiring full synchronization
                        # on CPU and GPUs before finishing. As a result, we store away
                        # the prior one to reduce the call overhead
                        __A					:					Optional[Any]								=		self.scaler.get_scale()
                        __A					:					Any								=		True
                   self.scaler.step(self.optimizer					,       a_	)
                   self.scaler.update()
                   __A					:					int								=		self.scaler.get_scale()
                   if not new_scale:
                        # If we reduced the loss scale, it means the optimizer step was skipped because of gradient overflow.
                        __A					:					List[Any]								=		scale_after < self._last_scale
                   __A					:					List[str]								=		scale_after

              else:
                   self.optimizer.step(a_	)
    def 						_a							(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         for param_group in self.optimizer.param_groups:
              __A					:					Union[str, Any]								=		[parameters_map.get(a_					,       a_	) for p in param_group["""params"""]]
    @property
    def 						_a							(  self	):




         '''simple docstring'''



         warnings.warn(
             'The `is_overflow` property is deprecated and will be removed in version 1.0 of Accelerate use '
             '`optimizer.step_was_skipped` instead.'					,       a_					,       )
         return self._is_overflow
    @property
    def 						_a							(  self	):




         '''simple docstring'''



         return self._is_overflow
    def __getstate__(  self	):




         '''simple docstring'''



         return self.__dict__.copy()

    def __setstate__(  self					,       __lowerCamelCase	):




         '''simple docstring'''



         self.__dict__.update(a_	)








'''simple docstring'''






import itertools




def        snake_case_   (	lowerCAmelCase_						)->						Dict:





       '''simple docstring'''


       return (
           int("""""".join(combination[0:2]						)						) * int("""""".join(combination[2:5]						)						)
           == int("""""".join(combination[5:9]						)						)
       ) or (
           int("""""".join(combination[0]						)						) * int("""""".join(combination[1:5]						)						)
           == int("""""".join(combination[5:9]						)						)
       )




def        snake_case_   (	)->						str:





       '''simple docstring'''


       return sum(
           {
               int("""""".join(pandigital[5:9]						)						)
               for pandigital in itertools.permutations("""123456789"""						)
               if is_combination_valid(lowerCAmelCase_						)
           }						)


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



