

'''simple docstring'''



from __future__ import annotations

from collections import Counter

def   lowerCamelCase__       (      a__)		->    list[int]:



    """simple docstring"""







    _snake_case : Optional[int]												=		[True] * n
    _snake_case : List[str]												=		False
    _snake_case : int												=		False
    _snake_case : Tuple												=		True

    for i in range(3			,      int(n**0.5 + 1)			,      2):
        _snake_case : int												=		i * 2
        while index < n:
            _snake_case : List[str]												=		False
            _snake_case : Union[str, Any]												=		index + i

    _snake_case : List[str]												=		[2]

    for i in range(3			,      a__			,      2):
        if is_prime[i]:
            primes.append(a__)

    return primes

def   lowerCamelCase__       (      a__)		->    list[list[int]]:



    """simple docstring"""







    _snake_case : Tuple												=		str(a__)
    _snake_case : str												=		[]
    _snake_case : Union[str, Any]												=		['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

    for duplicate in Counter(a__) - Counter(set(a__)):
        _snake_case : List[Any]												=		[int(number_str.replace(a__			,      a__)) for digit in digits]
        replacements.append(a__)

    return replacements

def   lowerCamelCase__       (      a__ = 8)		->    int:



    """simple docstring"""







    _snake_case : Any												=		set()

    # Filter primes with less than 3 replaceable digits
    _snake_case : List[Any]												=		{
        x for x in set(prime_sieve(1_0_0_0_0_0_0)) if len(str(a__)) - len(set(str(a__))) >= 3
    }

    for prime in primes:
        if prime in numbers_checked:
            continue

        _snake_case : int												=		digit_replacements(a__)

        for family in replacements:
            numbers_checked.update(a__)
            _snake_case : Union[str, Any]												=		primes.intersection(a__)

            if len(a__) != family_length:
                continue

            return min(a__)

    return -1


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






'''simple docstring'''



from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import ConvNextConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers import TFConvNextForImageClassification, TFConvNextModel


if is_vision_available():
   from PIL import Image

   from transformers import ConvNextImageProcessor

class 			SCREAMING_SNAKE_CASE					:






      '''simple docstring'''






      def __init__(					self :		Optional[int]     ,					snake_case :		Union[str, Any]     ,					snake_case :		Optional[int]=13     ,					snake_case :		Union[str, Any]=32     ,					snake_case :		List[Any]=3     ,					snake_case :		int=4     ,					snake_case :		List[Any]=[10, 20, 30, 40]     ,					snake_case :		List[str]=[2, 2, 3, 2]     ,					snake_case :		List[str]=True     ,					snake_case :		Optional[int]=True     ,					snake_case :		Union[str, Any]=37     ,					snake_case :		Any="gelu"     ,					snake_case :		Any=10     ,					snake_case :		Optional[Any]=0.02     ,					snake_case :		List[str]=3     ,					snake_case :		Any=None     ,					):



          """simple docstring"""





          _snake_case : Optional[Any]												=		parent
          _snake_case : Any												=		batch_size
          _snake_case : int												=		image_size
          _snake_case : int												=		num_channels
          _snake_case : int												=		num_stages
          _snake_case : Optional[int]												=		hidden_sizes
          _snake_case : Tuple												=		depths
          _snake_case : Optional[int]												=		is_training
          _snake_case : Tuple												=		use_labels
          _snake_case : str												=		intermediate_size
          _snake_case : Any												=		hidden_act
          _snake_case : Union[str, Any]												=		type_sequence_label_size
          _snake_case : Tuple												=		initializer_range
          _snake_case : List[Any]												=		scope




      def 	__UpperCAmelCase			(					self :		List[str]   ):



          """simple docstring"""





          _snake_case : str												=		floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )

          _snake_case : Any												=		None
          if self.use_labels:
              _snake_case : str												=		ids_tensor([self.batch_size]     ,					self.type_sequence_label_size   )

          _snake_case : Any												=		self.get_config()

          return config, pixel_values, labels




      def 	__UpperCAmelCase			(					self :		Union[str, Any]   ):



          """simple docstring"""





          return ConvNextConfig(
              num_channels=self.num_channels     ,					hidden_sizes=self.hidden_sizes     ,					depths=self.depths     ,					num_stages=self.num_stages     ,					hidden_act=self.hidden_act     ,					is_decoder=snake_case     ,					initializer_range=self.initializer_range     ,					)




      def 	__UpperCAmelCase			(					self :		int     ,					snake_case :		Optional[Any]     ,					snake_case :		str     ,					snake_case :		Optional[int]   ):



          """simple docstring"""





          _snake_case : Optional[int]												=		TFConvNextModel(config=snake_case   )
          _snake_case : Tuple												=		model(snake_case     ,					training=snake_case   )
          # expected last hidden states: B, C, H // 32, W // 32
          self.parent.assertEqual(
              result.last_hidden_state.shape     ,					(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)     ,					)




      def 	__UpperCAmelCase			(					self :		Any     ,					snake_case :		int     ,					snake_case :		List[str]     ,					snake_case :		List[Any]   ):



          """simple docstring"""





          _snake_case : int												=		self.type_sequence_label_size
          _snake_case : str												=		TFConvNextForImageClassification(snake_case   )
          _snake_case : Any												=		model(snake_case     ,					labels=snake_case     ,					training=snake_case   )
          self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.type_sequence_label_size)   )




      def 	__UpperCAmelCase			(					self :		Any   ):



          """simple docstring"""





          _snake_case : Union[str, Any]												=		self.prepare_config_and_inputs()
          _snake_case					,							_snake_case					,							_snake_case : Optional[int]												=		config_and_inputs
          _snake_case : Tuple												=		{'pixel_values': pixel_values}
          return config, inputs_dict



@require_tf
class 			SCREAMING_SNAKE_CASE					(							lowercase_      ,lowercase_      ,unittest.TestCase					):






      '''simple docstring'''






      SCREAMING_SNAKE_CASE__ :				List[Any]    =				(TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
      SCREAMING_SNAKE_CASE__ :				Tuple    =				(
          {'''feature-extraction''': TFConvNextModel, '''image-classification''': TFConvNextForImageClassification}
          if is_tf_available()
          else {}
      )

      SCREAMING_SNAKE_CASE__ :				Optional[int]    =				False
      SCREAMING_SNAKE_CASE__ :				str    =				False
      SCREAMING_SNAKE_CASE__ :				Optional[Any]    =				False
      SCREAMING_SNAKE_CASE__ :				str    =				False
      SCREAMING_SNAKE_CASE__ :				Any    =				False




      def 	__UpperCAmelCase			(					self :		List[str]   ):



          """simple docstring"""





          _snake_case : Optional[int]												=		TFConvNextModelTester(self   )
          _snake_case : Any												=		ConfigTester(
              self     ,					config_class=snake_case     ,					has_text_modality=snake_case     ,					hidden_size=37     ,					)




      @unittest.skip(reason='ConvNext does not use inputs_embeds'   )
      def 	__UpperCAmelCase			(					self :		Any   ):



          """simple docstring"""





          pass




      @unittest.skipIf(
          not is_tf_available() or len(tf.config.list_physical_devices('GPU'   )   ) == 0     ,					reason='TF does not support backprop for grouped convolutions on CPU.'     ,					)
      @slow
      def 	__UpperCAmelCase			(					self :		Optional[Any]   ):



          """simple docstring"""





          super().test_keras_fit()




      @unittest.skip(reason='ConvNext does not support input and output embeddings'   )
      def 	__UpperCAmelCase			(					self :		Tuple   ):



          """simple docstring"""





          pass




      def 	__UpperCAmelCase			(					self :		Optional[int]   ):



          """simple docstring"""





          _snake_case					,							_snake_case : Optional[Any]												=		self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
              _snake_case : str												=		model_class(snake_case   )
              _snake_case : int												=		inspect.signature(model.call   )
              # signature.parameters is an OrderedDict => so arg_names order is deterministic
              _snake_case : Dict												=		[*signature.parameters.keys()]

              _snake_case : str												=		['pixel_values']
              self.assertListEqual(arg_names[:1]     ,					snake_case   )




      def 	__UpperCAmelCase			(					self :		Optional[int]   ):



          """simple docstring"""





          _snake_case : Optional[Any]												=		self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*snake_case   )




      @unittest.skipIf(
          not is_tf_available() or len(tf.config.list_physical_devices('GPU'   )   ) == 0     ,					reason='TF does not support backprop for grouped convolutions on CPU.'     ,					)
      def 	__UpperCAmelCase			(					self :		Dict   ):



          """simple docstring"""





          super().test_dataset_conversion()




      def 	__UpperCAmelCase			(					self :		List[Any]   ):



          """simple docstring"""





          def check_hidden_states_output(snake_case :		Union[str, Any]     ,					snake_case :		str     ,					snake_case :		Dict   ):
              _snake_case : Any												=		model_class(snake_case   )

              _snake_case : Tuple												=		model(**self._prepare_for_class(snake_case     ,					snake_case   )   )
              _snake_case : Tuple												=		outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

              _snake_case : Optional[Any]												=		self.model_tester.num_stages
              self.assertEqual(len(snake_case   )     ,					expected_num_stages + 1   )

              # ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
              self.assertListEqual(
                  list(hidden_states[0].shape[-2:]   )     ,					[self.model_tester.image_size // 4, self.model_tester.image_size // 4]     ,					)

          _snake_case					,							_snake_case : Optional[int]												=		self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
              _snake_case : int												=		True
              check_hidden_states_output(snake_case     ,					snake_case     ,					snake_case   )

              # check that output_hidden_states also work using config
              del inputs_dict["output_hidden_states"]
              _snake_case : Optional[Any]												=		True

              check_hidden_states_output(snake_case     ,					snake_case     ,					snake_case   )




      def 	__UpperCAmelCase			(					self :		Optional[int]   ):



          """simple docstring"""





          _snake_case					,							_snake_case : Any												=		self.model_tester.prepare_config_and_inputs_for_common()

          def check_equivalence(snake_case :		Any     ,					snake_case :		Tuple     ,					snake_case :		List[str]     ,					snake_case :		Dict={}   ):
              _snake_case : Union[str, Any]												=		model(snake_case     ,					return_dict=snake_case     ,					**snake_case   )
              _snake_case : Dict												=		model(snake_case     ,					return_dict=snake_case     ,					**snake_case   ).to_tuple()

              def recursive_check(snake_case :		Dict     ,					snake_case :		Tuple   ):
                  if isinstance(snake_case     ,					(List, Tuple)   ):
                      for tuple_iterable_value, dict_iterable_value in zip(snake_case     ,					snake_case   ):
                          recursive_check(snake_case     ,					snake_case   )
                  elif tuple_object is None:
                      return
                  else:
                      self.assertTrue(
                          all(tf.equal(snake_case     ,					snake_case   )   )     ,					msg=(
                              'Tuple and dict output are not equal. Difference:'
                              F""" {tf.math.reduce_max(tf.abs(tuple_object - dict_object   )   )}"""
                          )     ,					)

                  recursive_check(snake_case     ,					snake_case   )

          for model_class in self.all_model_classes:
              _snake_case : Any												=		model_class(snake_case   )

              _snake_case : List[str]												=		self._prepare_for_class(snake_case     ,					snake_case   )
              _snake_case : Optional[int]												=		self._prepare_for_class(snake_case     ,					snake_case   )
              check_equivalence(snake_case     ,					snake_case     ,					snake_case   )

              _snake_case : Optional[int]												=		self._prepare_for_class(snake_case     ,					snake_case     ,					return_labels=snake_case   )
              _snake_case : Union[str, Any]												=		self._prepare_for_class(snake_case     ,					snake_case     ,					return_labels=snake_case   )
              check_equivalence(snake_case     ,					snake_case     ,					snake_case   )

              _snake_case : Any												=		self._prepare_for_class(snake_case     ,					snake_case   )
              _snake_case : Optional[Any]												=		self._prepare_for_class(snake_case     ,					snake_case   )
              check_equivalence(snake_case     ,					snake_case     ,					snake_case     ,					{'output_hidden_states': True}   )

              _snake_case : str												=		self._prepare_for_class(snake_case     ,					snake_case     ,					return_labels=snake_case   )
              _snake_case : Any												=		self._prepare_for_class(snake_case     ,					snake_case     ,					return_labels=snake_case   )
              check_equivalence(snake_case     ,					snake_case     ,					snake_case     ,					{'output_hidden_states': True}   )




      def 	__UpperCAmelCase			(					self :		str   ):



          """simple docstring"""





          _snake_case : List[str]												=		self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*snake_case   )




      @slow
      def 	__UpperCAmelCase			(					self :		str   ):



          """simple docstring"""





          _snake_case : Optional[Any]												=		TFConvNextModel.from_pretrained('facebook/convnext-tiny-224'   )
          self.assertIsNotNone(snake_case   )



def   lowerCamelCase__       (      )		->    int:



    """simple docstring"""







    _snake_case : Any												=		Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
    return image




@require_tf
@require_vision
class 			SCREAMING_SNAKE_CASE					(							unittest.TestCase					):






      '''simple docstring'''






      @cached_property
      def 	__UpperCAmelCase			(					self :		Optional[int]   ):



          """simple docstring"""





          return ConvNextImageProcessor.from_pretrained('facebook/convnext-tiny-224'   ) if is_vision_available() else None




      @slow
      def 	__UpperCAmelCase			(					self :		int   ):



          """simple docstring"""





          _snake_case : List[Any]												=		TFConvNextForImageClassification.from_pretrained('facebook/convnext-tiny-224'   )

          _snake_case : Optional[int]												=		self.default_image_processor
          _snake_case : Dict												=		prepare_img()
          _snake_case : str												=		image_processor(images=snake_case     ,					return_tensors='tf'   )

          # forward pass
          _snake_case : Optional[int]												=		model(**snake_case   )

          # verify the logits
          _snake_case : List[Any]												=		tf.TensorShape((1, 1000)   )
          self.assertEqual(outputs.logits.shape     ,					snake_case   )

          _snake_case : Union[str, Any]												=		tf.constant([-0.0260, -0.4739, 0.1911]   )

          tf.debugging.assert_near(outputs.logits[0, :3]     ,					snake_case     ,					atol=1e-4   )



