




from __future__ import annotations

import unittest

from transformers import MPNetConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
					import tensorflow as tf

					from transformers.models.mpnet.modeling_tf_mpnet import (
					    TFMPNetForMaskedLM,
					    TFMPNetForMultipleChoice,
					    TFMPNetForQuestionAnswering,
					    TFMPNetForSequenceClassification,
					    TFMPNetForTokenClassification,
					    TFMPNetModel,
					)

class __UpperCamelCase    :






					'''simple docstring'''



					def __init__(							self							,			lowerCamelCase__							,			lowerCamelCase__=1_3							,			lowerCamelCase__=7							,			lowerCamelCase__=True							,			lowerCamelCase__=True							,			lowerCamelCase__=False							,			lowerCamelCase__=True							,			lowerCamelCase__=9_9							,			lowerCamelCase__=6_4							,			lowerCamelCase__=2							,			lowerCamelCase__=4							,			lowerCamelCase__=6_4							,			lowerCamelCase__="gelu"							,			lowerCamelCase__=0.1							,			lowerCamelCase__=0.1							,			lowerCamelCase__=5_1_2							,			lowerCamelCase__=1_6							,			lowerCamelCase__=2							,			lowerCamelCase__=0.02							,			lowerCamelCase__=3							,			lowerCamelCase__=4							,			lowerCamelCase__=None							,			):
						UpperCAmelCase__:  Dict		       =   parent
						UpperCAmelCase__:  Optional[int]		       =   batch_size
						UpperCAmelCase__:  Optional[int]		       =   seq_length
						UpperCAmelCase__:  Union[str, Any]		       =   is_training
						UpperCAmelCase__:  List[Any]		       =   use_input_mask
						UpperCAmelCase__:  List[str]		       =   use_token_type_ids
						UpperCAmelCase__:  Tuple		       =   use_labels
						UpperCAmelCase__:  Any		       =   vocab_size
						UpperCAmelCase__:  Union[str, Any]		       =   hidden_size
						UpperCAmelCase__:  int		       =   num_hidden_layers
						UpperCAmelCase__:  Tuple		       =   num_attention_heads
						UpperCAmelCase__:  List[Any]		       =   intermediate_size
						UpperCAmelCase__:  Optional[Any]		       =   hidden_act
						UpperCAmelCase__:  Optional[int]		       =   hidden_dropout_prob
						UpperCAmelCase__:  Optional[Any]		       =   attention_probs_dropout_prob
						UpperCAmelCase__:  List[Any]		       =   max_position_embeddings
						UpperCAmelCase__:  Dict		       =   type_vocab_size
						UpperCAmelCase__:  Optional[Any]		       =   type_sequence_label_size
						UpperCAmelCase__:  int		       =   initializer_range
						UpperCAmelCase__:  List[Any]		       =   num_labels
						UpperCAmelCase__:  List[Any]		       =   num_choices
						UpperCAmelCase__:  Tuple		       =   scope





					def       _UpperCAmelCase						(							self	):
						UpperCAmelCase__:  str		       =   ids_tensor([self.batch_size, self.seq_length]							,			self.vocab_size	)

						UpperCAmelCase__:  Dict		       =   None
						if self.use_input_mask:
							UpperCAmelCase__:  str		       =   random_attention_mask([self.batch_size, self.seq_length]	)

						UpperCAmelCase__:  Optional[int]		       =   None
						UpperCAmelCase__:  Union[str, Any]		       =   None
						UpperCAmelCase__:  Optional[Any]		       =   None
						if self.use_labels:
							UpperCAmelCase__:  str		       =   ids_tensor([self.batch_size]							,			self.type_sequence_label_size	)
							UpperCAmelCase__:  List[str]		       =   ids_tensor([self.batch_size, self.seq_length]							,			self.num_labels	)
							UpperCAmelCase__:  Union[str, Any]		       =   ids_tensor([self.batch_size]							,			self.num_choices	)

						UpperCAmelCase__:  int		       =   MPNetConfig(
						    vocab_size=self.vocab_size							,			hidden_size=self.hidden_size							,			num_hidden_layers=self.num_hidden_layers							,			num_attention_heads=self.num_attention_heads							,			intermediate_size=self.intermediate_size							,			hidden_act=self.hidden_act							,			hidden_dropout_prob=self.hidden_dropout_prob							,			attention_probs_dropout_prob=self.attention_probs_dropout_prob							,			max_position_embeddings=self.max_position_embeddings							,			initializer_range=self.initializer_range							,			)
						return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
						UpperCAmelCase__:  Union[str, Any]		       =   TFMPNetModel(config=lowercase_	)
						UpperCAmelCase__:  Any		       =   {"input_ids": input_ids, "attention_mask": input_mask}
						UpperCAmelCase__:  int		       =   model(lowercase_	)
						UpperCAmelCase__:  int		       =   [input_ids, input_mask]
						UpperCAmelCase__:  Any		       =   model(lowercase_	)
						self.parent.assertEqual(result.last_hidden_state.shape							,			(self.batch_size, self.seq_length, self.hidden_size)	)





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
						UpperCAmelCase__:  str		       =   TFMPNetForMaskedLM(config=lowercase_	)
						UpperCAmelCase__:  str		       =   {"input_ids": input_ids, "attention_mask": input_mask}
						UpperCAmelCase__:  List[str]		       =   model(lowercase_	)
						self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.seq_length, self.vocab_size)	)





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
						UpperCAmelCase__:  List[Any]		       =   TFMPNetForQuestionAnswering(config=lowercase_	)
						UpperCAmelCase__:  Optional[Any]		       =   {
						    "input_ids": input_ids,
						    "attention_mask": input_mask,
						}
						UpperCAmelCase__:  List[Any]		       =   model(lowercase_	)
						self.parent.assertEqual(result.start_logits.shape							,			(self.batch_size, self.seq_length)	)
						self.parent.assertEqual(result.end_logits.shape							,			(self.batch_size, self.seq_length)	)





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
						UpperCAmelCase__:  List[str]		       =   self.num_labels
						UpperCAmelCase__:  Tuple		       =   TFMPNetForSequenceClassification(lowercase_	)
						UpperCAmelCase__:  List[str]		       =   {"input_ids": input_ids, "attention_mask": input_mask}
						UpperCAmelCase__:  Dict		       =   model(lowercase_	)
						self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.num_labels)	)





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
						UpperCAmelCase__:  Optional[int]		       =   self.num_choices
						UpperCAmelCase__:  Union[str, Any]		       =   TFMPNetForMultipleChoice(lowercase_	)
						UpperCAmelCase__:  int		       =   tf.tile(tf.expand_dims(lowercase_							,			1	)							,			(1, self.num_choices, 1)	)
						UpperCAmelCase__:  str		       =   tf.tile(tf.expand_dims(lowercase_							,			1	)							,			(1, self.num_choices, 1)	)
						UpperCAmelCase__:  List[str]		       =   {
						    "input_ids": multiple_choice_inputs_ids,
						    "attention_mask": multiple_choice_input_mask,
						}
						UpperCAmelCase__:  Optional[Any]		       =   model(lowercase_	)
						self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.num_choices)	)





					def       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
						UpperCAmelCase__:  int		       =   self.num_labels
						UpperCAmelCase__:  Union[str, Any]		       =   TFMPNetForTokenClassification(lowercase_	)
						UpperCAmelCase__:  Optional[Any]		       =   {"input_ids": input_ids, "attention_mask": input_mask}
						UpperCAmelCase__:  Optional[int]		       =   model(lowercase_	)
						self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.seq_length, self.num_labels)	)





					def       _UpperCAmelCase						(							self	):
						UpperCAmelCase__:  Any		       =   self.prepare_config_and_inputs()
						((UpperCAmelCase__)       ,	(UpperCAmelCase__)       ,	(UpperCAmelCase__)       ,	(UpperCAmelCase__)       ,	(UpperCAmelCase__)       ,	(UpperCAmelCase__)):  Dict		       =   config_and_inputs
						UpperCAmelCase__:  List[Any]		       =   {"input_ids": input_ids, "attention_mask": input_mask}
						return config, inputs_dict

@require_tf
class __UpperCamelCase    (							lowerCamelCase__				,lowerCamelCase__				,unittest.TestCase		):






					'''simple docstring'''



					__magic_name__     			=      (
					    (
					        TFMPNetForMaskedLM,
					        TFMPNetForMultipleChoice,
					        TFMPNetForQuestionAnswering,
					        TFMPNetForSequenceClassification,
					        TFMPNetForTokenClassification,
					        TFMPNetModel,
					    )
					    if is_tf_available()
					    else ()
					)
					__magic_name__     			=      (
					    {
					        'feature-extraction': TFMPNetModel,
					        'fill-mask': TFMPNetForMaskedLM,
					        'question-answering': TFMPNetForQuestionAnswering,
					        'text-classification': TFMPNetForSequenceClassification,
					        'token-classification': TFMPNetForTokenClassification,
					        'zero-shot': TFMPNetForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					__magic_name__     			=      False
					__magic_name__     			=      False





					def       _UpperCAmelCase						(							self	):
						UpperCAmelCase__:  Optional[Any]		       =   TFMPNetModelTester(self	)
						UpperCAmelCase__:  Optional[int]		       =   ConfigTester(self							,			config_class=lowercase_							,			hidden_size=3_7	)





					def       _UpperCAmelCase						(							self	):
						self.config_tester.run_common_tests()





					def       _UpperCAmelCase						(							self	):
						UpperCAmelCase__:  Union[str, Any]		       =   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_model(*lowercase_	)





					def       _UpperCAmelCase						(							self	):
						UpperCAmelCase__:  Any		       =   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_for_masked_lm(*lowercase_	)





					def       _UpperCAmelCase						(							self	):
						UpperCAmelCase__:  Any		       =   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_for_question_answering(*lowercase_	)





					def       _UpperCAmelCase						(							self	):
						UpperCAmelCase__:  List[Any]		       =   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowercase_	)





					def       _UpperCAmelCase						(							self	):
						UpperCAmelCase__:  Optional[int]		       =   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowercase_	)





					def       _UpperCAmelCase						(							self	):
						UpperCAmelCase__:  List[Any]		       =   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_mpnet_for_token_classification(*lowercase_	)





					@slow
					def       _UpperCAmelCase						(							self	):






						for model_name in ["microsoft/mpnet-base"]:
							UpperCAmelCase__:  List[str]		       =   TFMPNetModel.from_pretrained(lowercase_	)
							self.assertIsNotNone(lowercase_	)

@require_tf
class __UpperCamelCase    (							unittest.TestCase		):






					'''simple docstring'''



					@slow
					def       _UpperCAmelCase						(							self	):
						UpperCAmelCase__:  Optional[Any]		       =   TFMPNetModel.from_pretrained("microsoft/mpnet-base"	)
						UpperCAmelCase__:  List[str]		       =   tf.constant([[0, 1, 2, 3, 4, 5]]	)
						UpperCAmelCase__:  int		       =   model(lowercase_	)[0]

						UpperCAmelCase__:  int		       =   [1, 6, 7_6_8]
						self.assertEqual(output.shape							,			lowercase_	)

						UpperCAmelCase__:  List[Any]		       =   tf.constant(
						    [
						        [
						            [-0.1_067_172, 0.08_216_473, 0.0_024_543],
						            [-0.03_465_879, 0.8_354_118, -0.03_252_288],
						            [-0.06_569_476, -0.12_424_111, -0.0_494_436],
						        ]
						    ]	)
						tf.debugging.assert_near(output[:, :3, :3]							,			lowercase_							,			atol=1e-4	)


from __future__ import annotations

from collections import Counter



def  _A  (			SCREAMING_SNAKE_CASE			):
	UpperCAmelCase__:  Optional[Any]		       =   [True] * n
	UpperCAmelCase__:  Any		       =   False
	UpperCAmelCase__:  Tuple		       =   False
	UpperCAmelCase__:  Optional[Any]		       =   True

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

	UpperCAmelCase__:  int		       =   [2]

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

	return primes



def  _A  (			SCREAMING_SNAKE_CASE			):
	UpperCAmelCase__:  List[Any]		       =   str(SCREAMING_SNAKE_CASE			)
	UpperCAmelCase__:  Tuple		       =   []
	UpperCAmelCase__:  Optional[int]		       =   ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]

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

	return replacements



def  _A  (			SCREAMING_SNAKE_CASE = 8			):
	UpperCAmelCase__:  Union[str, Any]		       =   set()

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

	for prime in primes:
		if prime in numbers_checked:
			continue

		UpperCAmelCase__:  Optional[int]		       =   digit_replacements(SCREAMING_SNAKE_CASE			)

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

			if len(SCREAMING_SNAKE_CASE			) != family_length:
				continue

			return min(SCREAMING_SNAKE_CASE			)

	return -1


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