code: 
  
  
  '''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 _SCREAMING_SNAKE_CASE   (A						,				A ) -> str:
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
  
         if isinstance(A						,				(list, tuple) ):
                return honor_type(A						,				(move_to_device(A						,				A ) for t in state) )
         elif isinstance(A						,				A ):
                return type(A )({k: move_to_device(A						,				A ) for k, v in state.items()} )
         elif isinstance(A						,				torch.Tensor ):
                return state.to(A )
         return state
  
  class 						__lowerCAmelCase		(torch.optim.Optimizer  ):
  
  
  
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def __init__(self					:					Tuple     ,		UpperCamelCase					:					Any     ,		UpperCamelCase					:					Dict=True     ,		UpperCamelCase					:					int=None				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				optimizer
               lowercase__       =				scaler
               lowercase__       =				AcceleratorState()
               lowercase__       =				GradientState()
               lowercase__       =				device_placement
               lowercase__       =				False
               lowercase__       =				None
  
               # Handle device placement
               if device_placement:
                      lowercase__       =				self.optimizer.state_dict()
                      if self.accelerator_state.distributed_type == DistributedType.TPU:
                             xm.send_cpu_data_to_device(UpperCamelCase     ,		self.accelerator_state.device				)
                      else:
                             lowercase__       =				move_to_device(UpperCamelCase     ,		self.accelerator_state.device				)
                      self.optimizer.load_state_dict(UpperCamelCase				)
  
  
  
        @property
        def    UpperCamelCase__	(self					:					Union[str, Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return self.optimizer.state
  
  
  
        @state.setter
        def    UpperCamelCase__	(self					:					Union[str, Any]     ,		UpperCamelCase					:					Optional[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				state
  
  
  
        @property
        def    UpperCamelCase__	(self					:					int				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return self.optimizer.param_groups
  
  
  
        @param_groups.setter
        def    UpperCamelCase__	(self					:					Union[str, Any]     ,		UpperCamelCase					:					Dict				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				param_groups
  
  
  
        @property
        def    UpperCamelCase__	(self					:					Tuple				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return self.optimizer.defaults
  
  
  
        @defaults.setter
        def    UpperCamelCase__	(self					:					Optional[int]     ,		UpperCamelCase					:					Union[str, Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               lowercase__       =				defaults
  
  
  
        def    UpperCamelCase__	(self					:					Tuple     ,		UpperCamelCase					:					List[str]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               self.optimizer.add_param_group(UpperCamelCase				)
  
  
  
        def    UpperCamelCase__	(self					:					int     ,		UpperCamelCase					:					str				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               if self.accelerator_state.distributed_type == DistributedType.TPU and self.device_placement:
                      xm.send_cpu_data_to_device(UpperCamelCase     ,		self.accelerator_state.device				)
               self.optimizer.load_state_dict(UpperCamelCase				)
  
  
  
        def    UpperCamelCase__	(self					:					Optional[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return self.optimizer.state_dict()
  
  
  
        def    UpperCamelCase__	(self					:					Dict     ,		UpperCamelCase					:					Dict=None				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               if self.gradient_state.sync_gradients:
                      lowercase__       =				'''set_to_none''' in inspect.signature(self.optimizer.zero_grad				).parameters
                      if accept_arg:
                             if set_to_none is None:
                                    lowercase__       =				False
                             self.optimizer.zero_grad(set_to_none=UpperCamelCase				)
                      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    UpperCamelCase__	(self					:					Union[str, Any]     ,		UpperCamelCase					:					Optional[int]=None				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               if self.gradient_state.sync_gradients:
                      if self.accelerator_state.distributed_type == DistributedType.TPU:
                             lowercase__       =				{'''closure''': closure} if closure is not None else {}
                             xm.optimizer_step(self.optimizer     ,		optimizer_args=UpperCamelCase				)
                      elif self.scaler is not None:
                             lowercase__       =				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
                                    lowercase__       =				self.scaler.get_scale()
                                    lowercase__       =				True
                             self.scaler.step(self.optimizer     ,		UpperCamelCase				)
                             self.scaler.update()
                             lowercase__       =				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.
                                    lowercase__       =				scale_after < self._last_scale
                             lowercase__       =				scale_after
  
                      else:
                             self.optimizer.step(UpperCamelCase				)
  
  
  
        def    UpperCamelCase__	(self					:					Union[str, Any]     ,		UpperCamelCase					:					Dict				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               for param_group in self.optimizer.param_groups:
                      lowercase__       =				[parameters_map.get(UpperCamelCase     ,		UpperCamelCase				) for p in param_group['''params''']]
  
  
  
        @property
        def    UpperCamelCase__	(self					:					Dict				):
  
               '''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.'''     ,		UpperCamelCase     ,		)
               return self._is_overflow
  
  
  
        @property
        def    UpperCamelCase__	(self					:					Optional[int]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return self._is_overflow
  
  
  
        def __getstate__(self					:					Optional[Any]				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               return self.__dict__.copy()
  
  
  
  
  
  
        def __setstate__(self					:					Optional[int]     ,		UpperCamelCase					:					int				):
  
               '''simple docstring'''
  
  
  
  
  
  
  
               self.__dict__.update(UpperCamelCase				)
  
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  from __future__ import annotations
  
  from collections import Counter
  
  def _SCREAMING_SNAKE_CASE   (A ) -> list[int]:
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
  
         lowercase__       =				[True] * n
         lowercase__       =				False
         lowercase__       =				False
         lowercase__       =				True
  
         for i in range(3						,				int(n**0.5 + 1 )						,				2 ):
                lowercase__       =				i * 2
                while index < n:
                       lowercase__       =				False
                       lowercase__       =				index + i
  
         lowercase__       =				[2]
  
         for i in range(3						,				A						,				2 ):
                if is_prime[i]:
                       primes.append(A )
  
         return primes
  
  def _SCREAMING_SNAKE_CASE   (A ) -> list[list[int]]:
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
  
         lowercase__       =				str(A )
         lowercase__       =				[]
         lowercase__       =				['''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''']
  
         for duplicate in Counter(A ) - Counter(set(A ) ):
                lowercase__       =				[int(number_str.replace(A						,				A ) ) for digit in digits]
                replacements.append(A )
  
         return replacements
  
  def _SCREAMING_SNAKE_CASE   (A = 8 ) -> int:
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
  
         lowercase__       =				set()
  
         # Filter primes with less than 3 replaceable digits
         lowercase__       =				{
             x for x in set(prime_sieve(1_000_000 ) ) if len(str(A ) ) - len(set(str(A ) ) ) >= 3
         }
  
         for prime in primes:
                if prime in numbers_checked:
                       continue
  
                lowercase__       =				digit_replacements(A )
  
                for family in replacements:
                       numbers_checked.update(A )
                       lowercase__       =				primes.intersection(A )
  
                       if len(A ) != family_length:
                              continue
  
                       return min(A )
  
         return -1
  
  
  if __name__ == "__main__":
   print(solution())
  
  
  
  
  