




from __future__ import annotations

import collections
import tempfile
import unittest

import numpy as np

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

from ...test_modeling_tf_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_tf_bert import TFBertModelTester
from ..clip.test_modeling_tf_clip import TFCLIPVisionModelTester
from ..deit.test_modeling_tf_deit import TFDeiTModelTester
from ..roberta.test_modeling_tf_roberta import TFRobertaModelTester
from ..vit.test_modeling_tf_vit import TFViTModelTester


if is_tf_available():
   from transformers import (
       TFBertModel,
       TFCLIPVisionModel,
       TFDeiTModel,
       TFRobertaModel,
       TFVisionTextDualEncoderModel,
       TFViTModel,
       VisionTextDualEncoderConfig,
   )

if is_vision_available():
   from PIL import Image

   from transformers import VisionTextDualEncoderProcessor

def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Optional[int]							)					-> str:
      if isinstance(__UpperCAmelCase			,			collections.abc.Iterable							):
            return x
      return (x, x)





@require_tf
class        lowerCamelCase_							:


 '''simple docstring'''







 def       lowerCAmelCase_  (							self  :		int				,				_lowerCAmelCase  :		Tuple				,				_lowerCAmelCase  :		Tuple						):
       pass



 def       lowerCAmelCase_  (							self  :		Any						):
       pass



 def       lowerCAmelCase_  (							self  :		Tuple						):
       pass



 def       lowerCAmelCase_  (							self  :		List[Any]				,				_lowerCAmelCase  :		List[str]				,				_lowerCAmelCase  :		Optional[Any]				,				_lowerCAmelCase  :		Any				,				_lowerCAmelCase  :		List[Any]				,				_lowerCAmelCase  :		Optional[Any]=None				,				**_lowerCAmelCase  :		List[str]						):
       SCREAMING_SNAKE_CASE_							=			VisionTextDualEncoderConfig.from_vision_text_configs(_lowerCAmelCase				,				_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel(_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			model(input_ids=_lowerCAmelCase				,				pixel_values=_lowerCAmelCase				,				attention_mask=_lowerCAmelCase						)

       self.assertEqual(output['text_embeds'].shape				,				(input_ids.shape[0], config.projection_dim)						)
       self.assertEqual(output['image_embeds'].shape				,				(pixel_values.shape[0], config.projection_dim)						)



 def       lowerCAmelCase_  (							self  :		Dict				,				_lowerCAmelCase  :		Any				,				_lowerCAmelCase  :		Optional[Any]				,				_lowerCAmelCase  :		Any				,				_lowerCAmelCase  :		Any				,				_lowerCAmelCase  :		Dict=None				,				**_lowerCAmelCase  :		Optional[Any]						):
       SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			self.get_vision_text_model(_lowerCAmelCase				,				_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase				,				text_model=_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			model(input_ids=_lowerCAmelCase				,				pixel_values=_lowerCAmelCase				,				attention_mask=_lowerCAmelCase						)

       self.assertEqual(output['text_embeds'].shape				,				(input_ids.shape[0], model.config.projection_dim)						)
       self.assertEqual(output['image_embeds'].shape				,				(pixel_values.shape[0], model.config.projection_dim)						)



 def       lowerCAmelCase_  (							self  :		Dict				,				_lowerCAmelCase  :		List[str]				,				_lowerCAmelCase  :		str				,				_lowerCAmelCase  :		Any				,				_lowerCAmelCase  :		str				,				_lowerCAmelCase  :		str=None				,				**_lowerCAmelCase  :		List[Any]						):
       SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			self.get_vision_text_model(_lowerCAmelCase				,				_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			{'vision_model': vision_model, 'text_model': text_model}
       SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel.from_vision_text_pretrained(**_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			model(input_ids=_lowerCAmelCase				,				pixel_values=_lowerCAmelCase				,				attention_mask=_lowerCAmelCase						)

       self.assertEqual(output['text_embeds'].shape				,				(input_ids.shape[0], model.config.projection_dim)						)
       self.assertEqual(output['image_embeds'].shape				,				(pixel_values.shape[0], model.config.projection_dim)						)



 def       lowerCAmelCase_  (							self  :		List[str]				,				_lowerCAmelCase  :		Optional[int]				,				_lowerCAmelCase  :		int				,				_lowerCAmelCase  :		str				,				_lowerCAmelCase  :		Optional[Any]				,				_lowerCAmelCase  :		List[str]=None				,				**_lowerCAmelCase  :		List[Any]						):
       SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			self.get_vision_text_model(_lowerCAmelCase				,				_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase				,				text_model=_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			model(input_ids=_lowerCAmelCase				,				pixel_values=_lowerCAmelCase				,				attention_mask=_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			output[0].numpy()

       with tempfile.TemporaryDirectory() as tmpdirname:
             model.save_pretrained(_lowerCAmelCase						)
             SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase						)

             SCREAMING_SNAKE_CASE_							=			model(input_ids=_lowerCAmelCase				,				pixel_values=_lowerCAmelCase				,				attention_mask=_lowerCAmelCase						)
             SCREAMING_SNAKE_CASE_							=			after_output[0].numpy()
             SCREAMING_SNAKE_CASE_							=			np.amax(np.abs(out_a - out_a						)						)
             self.assertLessEqual(_lowerCAmelCase				,				1E-5						)



 def       lowerCAmelCase_  (							self  :		Optional[int]				,				_lowerCAmelCase  :		int				,				_lowerCAmelCase  :		Union[str, Any]				,				_lowerCAmelCase  :		List[str]				,				_lowerCAmelCase  :		Dict				,				_lowerCAmelCase  :		Any=None				,				**_lowerCAmelCase  :		List[str]						):
       SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			self.get_vision_text_model(_lowerCAmelCase				,				_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase				,				text_model=_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			model(
           input_ids=_lowerCAmelCase				,				pixel_values=_lowerCAmelCase				,				attention_mask=_lowerCAmelCase				,				output_attentions=_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			output.vision_model_output.attentions
       self.assertEqual(len(_lowerCAmelCase						)				,				vision_config.num_hidden_layers						)

       # in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
       SCREAMING_SNAKE_CASE_							=			to_atuple(vision_model.config.image_size						)
       SCREAMING_SNAKE_CASE_							=			to_atuple(vision_model.config.patch_size						)
       SCREAMING_SNAKE_CASE_							=			(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
       SCREAMING_SNAKE_CASE_							=			num_patches + 1
       self.assertEqual(vision_attentions[0].shape[-3:]				,				(vision_config.num_attention_heads, seq_len, seq_len)						)

       SCREAMING_SNAKE_CASE_							=			output.text_model_output.attentions
       self.assertEqual(len(_lowerCAmelCase						)				,				text_config.num_hidden_layers						)

       self.assertEqual(
           text_attentions[0].shape[-3:]				,				(text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])				,				)



 def       lowerCAmelCase_  (							self  :		Union[str, Any]				,				_lowerCAmelCase  :		np.ndarray				,				_lowerCAmelCase  :		np.ndarray				,				_lowerCAmelCase  :		float						):
       SCREAMING_SNAKE_CASE_							=			np.abs((a - b)						).max()
       self.assertLessEqual(_lowerCAmelCase				,				_lowerCAmelCase				,				F"Difference between torch and flax is {diff} (>= {tol})."						)



 def       lowerCAmelCase_  (							self  :		List[Any]						):
       SCREAMING_SNAKE_CASE_							=			self.prepare_config_and_inputs()
       self.check_vision_text_dual_encoder_model(**_lowerCAmelCase						)



 def       lowerCAmelCase_  (							self  :		str						):
       SCREAMING_SNAKE_CASE_							=			self.prepare_config_and_inputs()
       self.check_model_from_pretrained_configs(**_lowerCAmelCase						)



 def       lowerCAmelCase_  (							self  :		Optional[int]						):
       SCREAMING_SNAKE_CASE_							=			self.prepare_config_and_inputs()
       self.check_vision_text_dual_encoder_from_pretrained(**_lowerCAmelCase						)



 def       lowerCAmelCase_  (							self  :		Optional[Any]						):
       SCREAMING_SNAKE_CASE_							=			self.prepare_config_and_inputs()
       self.check_save_load(**_lowerCAmelCase						)



 def       lowerCAmelCase_  (							self  :		List[Any]						):
       SCREAMING_SNAKE_CASE_							=			self.prepare_config_and_inputs()
       self.check_vision_text_output_attention(**_lowerCAmelCase						)




 @slow
 def       lowerCAmelCase_  (							self  :		str						):
       SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			self.get_pretrained_model_and_inputs()

       SCREAMING_SNAKE_CASE_							=			model_a(**_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			outputs[0].numpy()

       with tempfile.TemporaryDirectory() as tmp_dirname:
             model_a.save_pretrained(_lowerCAmelCase						)
             SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase						)

             SCREAMING_SNAKE_CASE_							=			model_a(**_lowerCAmelCase						)
             SCREAMING_SNAKE_CASE_							=			after_outputs[0].numpy()
             SCREAMING_SNAKE_CASE_							=			np.amax(np.abs(out_a - out_a						)						)
             self.assertLessEqual(_lowerCAmelCase				,				1E-5						)





@require_tf
class        lowerCamelCase_							(      _SCREAMING_SNAKE_CASE       ,   unittest.TestCase					):


 '''simple docstring'''







 def       lowerCAmelCase_  (							self  :		int						):
       SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel.from_vision_text_pretrained(
           'hf-internal-testing/tiny-random-vit'				,				'hf-internal-testing/tiny-random-bert'						)
       SCREAMING_SNAKE_CASE_							=			13
       SCREAMING_SNAKE_CASE_							=			floats_tensor(
           [
               batch_size,
               model.vision_model.config.num_channels,
               model.vision_model.config.image_size,
               model.vision_model.config.image_size,
           ]						)
       SCREAMING_SNAKE_CASE_							=			ids_tensor([batch_size, 4]				,				model.text_model.config.vocab_size						)
       SCREAMING_SNAKE_CASE_							=			random_attention_mask([batch_size, 4]						)
       SCREAMING_SNAKE_CASE_							=			{'pixel_values': pixel_values, 'input_ids': input_ids, 'attention_mask': attention_mask}

       return model, inputs



 def       lowerCAmelCase_  (							self  :		Optional[Any]				,				_lowerCAmelCase  :		str				,				_lowerCAmelCase  :		Any						):
       SCREAMING_SNAKE_CASE_							=			TFViTModel(_lowerCAmelCase				,				name='vision_model'						)
       SCREAMING_SNAKE_CASE_							=			TFBertModel(_lowerCAmelCase				,				name='text_model'						)
       return vision_model, text_model




 def       lowerCAmelCase_  (							self  :		Optional[Any]						):
       SCREAMING_SNAKE_CASE_							=			TFViTModelTester(self						)
       SCREAMING_SNAKE_CASE_							=			TFBertModelTester(self						)
       SCREAMING_SNAKE_CASE_							=			vit_model_tester.prepare_config_and_inputs()
       SCREAMING_SNAKE_CASE_							=			bert_model_tester.prepare_config_and_inputs()

       SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			vision_config_and_inputs

       (
           (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, 
       )							=			text_config_and_inputs

       return {
           "text_config": text_config,
           "vision_config": vision_config,
           "pixel_values": pixel_values,
           "attention_mask": input_mask,
           "input_ids": input_ids,
           "text_token_type_ids": token_type_ids,
           "text_sequence_labels": sequence_labels,
           "text_token_labels": token_labels,
           "text_choice_labels": choice_labels,
       }





@require_tf
class        lowerCamelCase_							(      _SCREAMING_SNAKE_CASE       ,   unittest.TestCase					):


 '''simple docstring'''







 def       lowerCAmelCase_  (							self  :		Union[str, Any]						):
       # DeiT repo doesn't have TF weights, but we don't actually use the weights at all so let's
       # just reinitialize it.
       SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel.from_vision_text_pretrained(
           'Rocketknight1/tiny-random-deit-tf'				,				'hf-internal-testing/tiny-random-roberta'						)
       SCREAMING_SNAKE_CASE_							=			13
       SCREAMING_SNAKE_CASE_							=			floats_tensor(
           [
               batch_size,
               model.vision_model.config.num_channels,
               model.vision_model.config.image_size,
               model.vision_model.config.image_size,
           ]						)
       SCREAMING_SNAKE_CASE_							=			ids_tensor([batch_size, 4]				,				model.text_model.config.vocab_size						)
       SCREAMING_SNAKE_CASE_							=			random_attention_mask([batch_size, 4]						)
       SCREAMING_SNAKE_CASE_							=			{'pixel_values': pixel_values, 'input_ids': input_ids, 'attention_mask': attention_mask}

       return model, inputs



 def       lowerCAmelCase_  (							self  :		Tuple				,				_lowerCAmelCase  :		int				,				_lowerCAmelCase  :		Optional[Any]				,				_lowerCAmelCase  :		Union[str, Any]				,				_lowerCAmelCase  :		Optional[Any]				,				_lowerCAmelCase  :		Optional[int]=None				,				**_lowerCAmelCase  :		Optional[Any]						):
       SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			self.get_vision_text_model(_lowerCAmelCase				,				_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase				,				text_model=_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			model(
           input_ids=_lowerCAmelCase				,				pixel_values=_lowerCAmelCase				,				attention_mask=_lowerCAmelCase				,				output_attentions=_lowerCAmelCase						)

       SCREAMING_SNAKE_CASE_							=			output.vision_model_output.attentions
       self.assertEqual(len(_lowerCAmelCase						)				,				vision_config.num_hidden_layers						)

       # in DEiT, the seq_len equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
       SCREAMING_SNAKE_CASE_							=			to_atuple(vision_model.config.image_size						)
       SCREAMING_SNAKE_CASE_							=			to_atuple(vision_model.config.patch_size						)
       SCREAMING_SNAKE_CASE_							=			(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
       SCREAMING_SNAKE_CASE_							=			num_patches + 2
       self.assertEqual(vision_attentions[0].shape[-3:]				,				(vision_config.num_attention_heads, seq_len, seq_len)						)

       SCREAMING_SNAKE_CASE_							=			output.text_model_output.attentions
       self.assertEqual(len(_lowerCAmelCase						)				,				text_config.num_hidden_layers						)

       self.assertEqual(
           text_attentions[0].shape[-3:]				,				(text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])				,				)



 def       lowerCAmelCase_  (							self  :		List[str]				,				_lowerCAmelCase  :		Optional[Any]				,				_lowerCAmelCase  :		Union[str, Any]						):
       SCREAMING_SNAKE_CASE_							=			TFDeiTModel(_lowerCAmelCase				,				name='vision_model'						)
       SCREAMING_SNAKE_CASE_							=			TFRobertaModel(_lowerCAmelCase				,				name='text_model'						)
       return vision_model, text_model




 def       lowerCAmelCase_  (							self  :		Any						):
       SCREAMING_SNAKE_CASE_							=			TFDeiTModelTester(self						)
       SCREAMING_SNAKE_CASE_							=			TFRobertaModelTester(self						)
       SCREAMING_SNAKE_CASE_							=			vit_model_tester.prepare_config_and_inputs()
       SCREAMING_SNAKE_CASE_							=			bert_model_tester.prepare_config_and_inputs()

       SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			vision_config_and_inputs

       (
           (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, 
       )							=			text_config_and_inputs

       return {
           "text_config": text_config,
           "vision_config": vision_config,
           "pixel_values": pixel_values,
           "attention_mask": input_mask,
           "input_ids": input_ids,
           "text_token_type_ids": token_type_ids,
           "text_sequence_labels": sequence_labels,
           "text_token_labels": token_labels,
           "text_choice_labels": choice_labels,
       }





@require_tf
class        lowerCamelCase_							(      _SCREAMING_SNAKE_CASE       ,   unittest.TestCase					):


 '''simple docstring'''







 def       lowerCAmelCase_  (							self  :		Optional[int]						):
       SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel.from_vision_text_pretrained(
           'Rocketknight1/tiny-random-clip-tf'				,				'hf-internal-testing/tiny-random-bert'						)
       SCREAMING_SNAKE_CASE_							=			13
       SCREAMING_SNAKE_CASE_							=			floats_tensor(
           [
               batch_size,
               model.vision_model.config.num_channels,
               model.vision_model.config.image_size,
               model.vision_model.config.image_size,
           ]						)
       SCREAMING_SNAKE_CASE_							=			ids_tensor([batch_size, 4]				,				model.text_model.config.vocab_size						)
       SCREAMING_SNAKE_CASE_							=			random_attention_mask([batch_size, 4]						)
       SCREAMING_SNAKE_CASE_							=			{'pixel_values': pixel_values, 'input_ids': input_ids, 'attention_mask': attention_mask}

       return model, inputs



 def       lowerCAmelCase_  (							self  :		str				,				_lowerCAmelCase  :		List[Any]				,				_lowerCAmelCase  :		List[Any]						):
       SCREAMING_SNAKE_CASE_							=			TFCLIPVisionModel(_lowerCAmelCase				,				name='vision_model'						)
       SCREAMING_SNAKE_CASE_							=			TFBertModel(_lowerCAmelCase				,				name='text_model'						)
       return vision_model, text_model




 def       lowerCAmelCase_  (							self  :		List[str]						):
       SCREAMING_SNAKE_CASE_							=			TFCLIPVisionModelTester(self						)
       SCREAMING_SNAKE_CASE_							=			TFBertModelTester(self						)
       SCREAMING_SNAKE_CASE_							=			clip_model_tester.prepare_config_and_inputs()
       SCREAMING_SNAKE_CASE_							=			bert_model_tester.prepare_config_and_inputs()

       SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			vision_config_and_inputs

       (
           (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, (
           SCREAMING_SNAKE_CASE_
       )						, 
       )							=			text_config_and_inputs

       return {
           "text_config": text_config,
           "vision_config": vision_config,
           "pixel_values": pixel_values,
           "attention_mask": input_mask,
           "input_ids": input_ids,
           "text_token_type_ids": token_type_ids,
           "text_sequence_labels": sequence_labels,
           "text_token_labels": token_labels,
           "text_choice_labels": choice_labels,
       }





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


 '''simple docstring'''







 @slow
 def       lowerCAmelCase_  (							self  :		str						):
       SCREAMING_SNAKE_CASE_							=			TFVisionTextDualEncoderModel.from_pretrained(
           'clip-italian/clip-italian'				,				logit_scale_init_value=1.0				,				from_pt=_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			VisionTextDualEncoderProcessor.from_pretrained('clip-italian/clip-italian'						)

       SCREAMING_SNAKE_CASE_							=			Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
       SCREAMING_SNAKE_CASE_							=			processor(
           text=['una foto di un gatto', 'una foto di un cane']				,				images=_lowerCAmelCase				,				padding=_lowerCAmelCase				,				return_tensors='np'						)

       SCREAMING_SNAKE_CASE_							=			model(**_lowerCAmelCase						)

       # verify the logits
       self.assertEqual(outputs.logits_per_image.shape				,				(inputs.pixel_values.shape[0], inputs.input_ids.shape[0])						)
       self.assertEqual(
           outputs.logits_per_text.shape				,				(inputs.input_ids.shape[0], inputs.pixel_values.shape[0])				,				)

       SCREAMING_SNAKE_CASE_							=			np.array([[1.228_4727, 0.310_4122]]						)

       self.assertTrue(np.allclose(outputs.logits_per_image.numpy()				,				_lowerCAmelCase				,				atol=1E-3						)						)





from math import sqrt

def 					UpperCAmelCase_							(      __UpperCAmelCase						:	int							)					-> bool:

      if 1 < number < 4:
            # 2 and 3 are primes
            return True
      elif number < 2 or number % 2 == 0 or number % 3 == 0:
            # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
            return False

      # All primes number are in format of 6k +/- 1
      for i in range(5			,			int(sqrt(__UpperCAmelCase							) + 1							)			,			6							):
            if number % i == 0 or number % (i + 2) == 0:
                  return False
      return True

def 					UpperCAmelCase_							(      __UpperCAmelCase						:	int = 1_00_01							)					-> int:
      SCREAMING_SNAKE_CASE_							=			0
      SCREAMING_SNAKE_CASE_							=			1
      while count != nth and number < 3:
            number += 1
            if is_prime(__UpperCAmelCase							):
                  count += 1
      while count != nth:
            number += 2
            if is_prime(__UpperCAmelCase							):
                  count += 1
      return number


if __name__ == "__main__":
   print(f'''{solution() = }''')