"""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      _lowercase						:

				def __init__(       self    :      List[Any]    ,      _lowercase    :      str    ,      _lowercase    :      List[str]=1_3    ,      _lowercase    :      Optional[Any]=3_2    ,      _lowercase    :      Union[str, Any]=3    ,      _lowercase    :      Optional[int]=4    ,      _lowercase    :      str=[1_0, 2_0, 3_0, 4_0]    ,      _lowercase    :      List[Any]=[2, 2, 3, 2]    ,      _lowercase    :      List[str]=True    ,      _lowercase    :      List[str]=True    ,      _lowercase    :      Tuple=3_7    ,      _lowercase    :      int="gelu"    ,      _lowercase    :      str=1_0    ,      _lowercase    :      Union[str, Any]=0.02    ,      _lowercase    :      int=3    ,      _lowercase    :      List[Any]=None    ,      ):


										'''simple docstring'''
										UpperCAmelCase__   		=						parent
										UpperCAmelCase__   		=						batch_size
										UpperCAmelCase__   		=						image_size
										UpperCAmelCase__   		=						num_channels
										UpperCAmelCase__   		=						num_stages
										UpperCAmelCase__   		=						hidden_sizes
										UpperCAmelCase__   		=						depths
										UpperCAmelCase__   		=						is_training
										UpperCAmelCase__   		=						use_labels
										UpperCAmelCase__   		=						intermediate_size
										UpperCAmelCase__   		=						hidden_act
										UpperCAmelCase__   		=						type_sequence_label_size
										UpperCAmelCase__   		=						initializer_range
										UpperCAmelCase__   		=						scope

				def     A	(       self    :      Dict       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

										UpperCAmelCase__   		=						None
										if self.use_labels:
																UpperCAmelCase__   		=						ids_tensor([self.batch_size]    ,      self.type_sequence_label_size       )

										UpperCAmelCase__   		=						self.get_config()

										return config, pixel_values, labels

				def     A	(       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=_lowercase    ,      initializer_range=self.initializer_range    ,      )

				def     A	(       self    :      int    ,      _lowercase    :      Tuple    ,      _lowercase    :      int    ,      _lowercase    :      int       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						TFConvNextModel(config=_lowercase       )
										UpperCAmelCase__   		=						model(_lowercase    ,      training=_lowercase       )
										# 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 // 3_2, self.image_size // 3_2)    ,      )

				def     A	(       self    :      Optional[Any]    ,      _lowercase    :      Dict    ,      _lowercase    :      List[Any]    ,      _lowercase    :      str       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.type_sequence_label_size
										UpperCAmelCase__   		=						TFConvNextForImageClassification(_lowercase       )
										UpperCAmelCase__   		=						model(_lowercase    ,      labels=_lowercase    ,      training=_lowercase       )
										self.parent.assertEqual(result.logits.shape    ,      (self.batch_size, self.type_sequence_label_size)       )

				def     A	(       self    :      Optional[int]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.prepare_config_and_inputs()
										UpperCAmelCase__   		=						config_and_inputs
										UpperCAmelCase__   		=						{"pixel_values": pixel_values}
										return config, inputs_dict


@require_tf
class      _lowercase						(				__A , __A , unittest.TestCase					):
				lowerCamelCase__									=    (TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
				lowerCamelCase__									=    (
				    {'feature-extraction': TFConvNextModel, 'image-classification': TFConvNextForImageClassification}
				    if is_tf_available()
				    else {}
				)

				lowerCamelCase__									=    False
				lowerCamelCase__									=    False
				lowerCamelCase__									=    False
				lowerCamelCase__									=    False
				lowerCamelCase__									=    False

				def     A	(       self    :      Optional[int]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						TFConvNextModelTester(self       )
										UpperCAmelCase__   		=						ConfigTester(
										    self    ,      config_class=_lowercase    ,      has_text_modality=_lowercase    ,      hidden_size=3_7    ,      )

				@unittest.skip(reason="""ConvNext does not use inputs_embeds"""       )
				def     A	(       self    :      Union[str, 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     A	(       self    :      Optional[int]       ):


										'''simple docstring'''
										super().test_keras_fit()

				@unittest.skip(reason="""ConvNext does not support input and output embeddings"""       )
				def     A	(       self    :      List[Any]       ):


										'''simple docstring'''
										pass

				def     A	(       self    :      Dict       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs_for_common()

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

																UpperCAmelCase__   		=						["pixel_values"]
																self.assertListEqual(arg_names[:1]    ,      _lowercase       )

				def     A	(       self    :      Dict       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*_lowercase       )

				@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     A	(       self    :      List[Any]       ):


										'''simple docstring'''
										super().test_dataset_conversion()

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


										'''simple docstring'''

										def check_hidden_states_output(_lowercase    :      Tuple    ,      _lowercase    :      List[Any]    ,      _lowercase    :      Optional[Any]       ):
																UpperCAmelCase__   		=						model_class(_lowercase       )

																UpperCAmelCase__   		=						model(**self._prepare_for_class(_lowercase    ,      _lowercase       )       )
																UpperCAmelCase__   		=						outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

																UpperCAmelCase__   		=						self.model_tester.num_stages
																self.assertEqual(len(_lowercase       )    ,      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]    ,      )

										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																UpperCAmelCase__   		=						True
																check_hidden_states_output(_lowercase    ,      _lowercase    ,      _lowercase       )

																# check that output_hidden_states also work using config
																del inputs_dict["output_hidden_states"]
																UpperCAmelCase__   		=						True

																check_hidden_states_output(_lowercase    ,      _lowercase    ,      _lowercase       )

				def     A	(       self    :      str       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs_for_common()

										def check_equivalence(_lowercase    :      str    ,      _lowercase    :      int    ,      _lowercase    :      str    ,      _lowercase    :      Tuple={}       ):
																UpperCAmelCase__   		=						model(_lowercase    ,      return_dict=_lowercase    ,      **_lowercase       )
																UpperCAmelCase__   		=						model(_lowercase    ,      return_dict=_lowercase    ,      **_lowercase       ).to_tuple()

																def recursive_check(_lowercase    :      Optional[int]    ,      _lowercase    :      Union[str, Any]       ):
																						if isinstance(_lowercase    ,      (List, Tuple)       ):
																												for tuple_iterable_value, dict_iterable_value in zip(_lowercase    ,      _lowercase       ):
																																		recursive_check(_lowercase    ,      _lowercase       )
																						elif tuple_object is None:
																												return
																						else:
																												self.assertTrue(
																												    all(tf.equal(_lowercase    ,      _lowercase       )       )    ,      msg=(
																												        """Tuple and dict output are not equal. Difference:"""
																												        f' {tf.math.reduce_max(tf.abs(tuple_object - dict_object       )       )}'
																												    )    ,      )

																						recursive_check(_lowercase    ,      _lowercase       )

										for model_class in self.all_model_classes:
																UpperCAmelCase__   		=						model_class(_lowercase       )

																UpperCAmelCase__   		=						self._prepare_for_class(_lowercase    ,      _lowercase       )
																UpperCAmelCase__   		=						self._prepare_for_class(_lowercase    ,      _lowercase       )
																check_equivalence(_lowercase    ,      _lowercase    ,      _lowercase       )

																UpperCAmelCase__   		=						self._prepare_for_class(_lowercase    ,      _lowercase    ,      return_labels=_lowercase       )
																UpperCAmelCase__   		=						self._prepare_for_class(_lowercase    ,      _lowercase    ,      return_labels=_lowercase       )
																check_equivalence(_lowercase    ,      _lowercase    ,      _lowercase       )

																UpperCAmelCase__   		=						self._prepare_for_class(_lowercase    ,      _lowercase       )
																UpperCAmelCase__   		=						self._prepare_for_class(_lowercase    ,      _lowercase       )
																check_equivalence(_lowercase    ,      _lowercase    ,      _lowercase    ,      {"""output_hidden_states""": True}       )

																UpperCAmelCase__   		=						self._prepare_for_class(_lowercase    ,      _lowercase    ,      return_labels=_lowercase       )
																UpperCAmelCase__   		=						self._prepare_for_class(_lowercase    ,      _lowercase    ,      return_labels=_lowercase       )
																check_equivalence(_lowercase    ,      _lowercase    ,      _lowercase    ,      {"""output_hidden_states""": True}       )

				def     A	(       self    :      List[str]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*_lowercase       )

				@slow
				def     A	(       self    :      Any       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						TFConvNextModel.from_pretrained("""facebook/convnext-tiny-224"""       )
										self.assertIsNotNone(_lowercase       )


def 					a__ (						):
						UpperCAmelCase__   		=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""     )
						return image







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

				@cached_property
				def     A	(       self    :      Optional[Any]       ):


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

				@slow
				def     A	(       self    :      Optional[int]       ):


										'''simple docstring'''
										UpperCAmelCase__   		=						TFConvNextForImageClassification.from_pretrained("""facebook/convnext-tiny-224"""       )

										UpperCAmelCase__   		=						self.default_image_processor
										UpperCAmelCase__   		=						prepare_img()
										UpperCAmelCase__   		=						image_processor(images=_lowercase    ,      return_tensors="""tf"""       )

										# forward pass
										UpperCAmelCase__   		=						model(**_lowercase       )

										# verify the logits
										UpperCAmelCase__   		=						tf.TensorShape((1, 1_0_0_0)       )
										self.assertEqual(outputs.logits.shape    ,      _lowercase       )

										UpperCAmelCase__   		=						tf.constant([-0.0260, -0.4739, 0.1911]       )

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


"""simple docstring"""







from __future__ import annotations

from collections import Counter


def 					a__ (						UpperCAmelCase__    :     int     )->		list[int]:
						UpperCAmelCase__   		=						[True] * n
						UpperCAmelCase__   		=						False
						UpperCAmelCase__   		=						False
						UpperCAmelCase__   		=						True

						for i in range(3						,     int(n**0.5 + 1     )						,     2     ):
												UpperCAmelCase__   		=						i * 2
												while index < n:
																		UpperCAmelCase__   		=						False
																		UpperCAmelCase__   		=						index + i

						UpperCAmelCase__   		=						[2]

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

						return primes


def 					a__ (						UpperCAmelCase__    :     int     )->		list[list[int]]:
						UpperCAmelCase__   		=						str(UpperCAmelCase__     )
						UpperCAmelCase__   		=						[]
						UpperCAmelCase__   		=						["""0""", """1""", """2""", """3""", """4""", """5""", """6""", """7""", """8""", """9"""]

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

						return replacements


def 					a__ (						UpperCAmelCase__    :     int = 8     )->		int:
						UpperCAmelCase__   		=						set()

						# Filter primes with less than 3 replaceable digits
						UpperCAmelCase__   		=						{
						    x for x in set(prime_sieve(1_0_0_0_0_0_0     )     ) if len(str(UpperCAmelCase__     )     ) - len(set(str(UpperCAmelCase__     )     )     ) >= 3
						}

						for prime in primes:
												if prime in numbers_checked:
																		continue

												UpperCAmelCase__   		=						digit_replacements(UpperCAmelCase__     )

												for family in replacements:
																		numbers_checked.update(UpperCAmelCase__     )
																		UpperCAmelCase__   		=						primes.intersection(UpperCAmelCase__     )

																		if len(UpperCAmelCase__     ) != family_length:
																								continue

																		return min(UpperCAmelCase__     )

						return -1


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

