code: from __future__ import annotations
  
  from collections import Counter
  
  def      SCREAMING_SNAKE_CASE_  (		snake_case__							)  ->			list[int]:
  							lowerCAmelCase				=	[True] * n
  							lowerCAmelCase				=	False
  							lowerCAmelCase				=	False
  							lowerCAmelCase				=	True
  
  							for i in range(3     ,						int(n**0.5 + 1							)     ,						2							):
  														lowerCAmelCase				=	i * 2
  														while index < n:
  																					lowerCAmelCase				=	False
  																					lowerCAmelCase				=	index + i
  
  							lowerCAmelCase				=	[2]
  
  							for i in range(3     ,						snake_case__     ,						2							):
  														if is_prime[i]:
  																					primes.append(snake_case__							)
  
  							return primes
  
  def      SCREAMING_SNAKE_CASE_  (		snake_case__							)  ->			list[list[int]]:
  							lowerCAmelCase				=	str(snake_case__							)
  							lowerCAmelCase				=	[]
  							lowerCAmelCase				=	['''0''', '''1''', '''2''', '''3''', '''4''', '''5''', '''6''', '''7''', '''8''', '''9''']
  
  							for duplicate in Counter(snake_case__							) - Counter(set(snake_case__							)							):
  														lowerCAmelCase				=	[int(number_str.replace(snake_case__     ,						snake_case__							)							) for digit in digits]
  														replacements.append(snake_case__							)
  
  							return replacements
  
  def      SCREAMING_SNAKE_CASE_  (		snake_case__ = 8							)  ->			int:
  							lowerCAmelCase				=	set()
  
  							# Filter primes with less than 3 replaceable digits
  							lowerCAmelCase				=	{
  							    x for x in set(prime_sieve(1_0_0_0_0_0_0							)							) if len(str(snake_case__							)							) - len(set(str(snake_case__							)							)							) >= 3
  							}
  
  							for prime in primes:
  														if prime in numbers_checked:
  																					continue
  
  														lowerCAmelCase				=	digit_replacements(snake_case__							)
  
  														for family in replacements:
  																					numbers_checked.update(snake_case__							)
  																					lowerCAmelCase				=	primes.intersection(snake_case__							)
  
  																					if len(snake_case__							) != family_length:
  																												continue
  
  																					return min(snake_case__							)
  
  							return -1
  
  
  if __name__ == "__main__":
  	print(solution())
  
  
  
  
style_context: import torch
  
  from accelerate import Accelerator, DistributedType
  
  
  
  
  class      lowercase_						:
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  	def __enter__(							self       )		->Dict:
  								if self.enabled:
  															lowerCAmelCase				=	self.model.no_sync()
  															self.model_sync_obj.__enter__()
  
  								return self
  
  
  	def __exit__(							self	,    __SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE       )		->Any:
  								if self.enabled:
  															# Average all models on exit
  															self._sync_and_avg_model_params()
  															self.model_sync_obj.__exit__(__SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE       )
  
  
  	def __init__(							self	,    __SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE = True       )		->Tuple:
  								if accelerator.distributed_type not in [
  								    DistributedType.NO,
  								    DistributedType.MULTI_CPU,
  								    DistributedType.MULTI_GPU,
  								]:
  															raise NotImplementedError('''LocalSGD is supported only for CPUs and GPUs (no DeepSpeed or MegatronLM)'''       )
  								lowerCAmelCase				=	enabled and accelerator.distributed_type != DistributedType.NO
  								lowerCAmelCase				=	0
  								if self.enabled:
  															lowerCAmelCase				=	accelerator
  															lowerCAmelCase				=	model
  															lowerCAmelCase				=	local_sgd_steps
  
  
  	def     SCREAMING_SNAKE_CASE_       (							self       )		->List[Any]:
  								self.num_steps += 1
  								if not self.enabled:
  															return
  
  								if self.num_steps % self.local_sgd_steps == 0:
  															self._sync_and_avg_model_params()
  
  
  
  
  	def     SCREAMING_SNAKE_CASE_       (							self       )		->Optional[int]:
  								self.accelerator.wait_for_everyone()
  								with self.accelerator.autocast():
  															for param in self.model.parameters():
  																						lowerCAmelCase				=	self.accelerator.reduce(param.data	,    reduction='''mean'''       )
  
  
  
  