


"""simple docstring"""






import inspect
import unittest

from transformers import MobileViTConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import MobileViTForImageClassification, MobileViTForSemanticSegmentation, MobileViTModel
  from transformers.models.mobilevit.modeling_mobilevit import MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from PIL import Image

  from transformers import MobileViTImageProcessor




class 							A_      (       _a ):


  def 							_lowercase					(			self:						List[Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Any							=     self.config_class(**self.inputs_dict    )
     self.parent.assertTrue(hasattr(__lowerCAmelCase							,"hidden_sizes"    )    )
     self.parent.assertTrue(hasattr(__lowerCAmelCase							,"neck_hidden_sizes"    )    )
     self.parent.assertTrue(hasattr(__lowerCAmelCase							,"num_attention_heads"    )    )




class 							A_      :


  def __init__(			self:						List[str]							,__lowerCAmelCase:						List[Any]							,__lowerCAmelCase:						List[Any]=13							,__lowerCAmelCase:						Any=32							,__lowerCAmelCase:						Optional[Any]=2							,__lowerCAmelCase:						Dict=3							,__lowerCAmelCase:						Any=640							,__lowerCAmelCase:						List[str]=4							,__lowerCAmelCase:						Dict="silu"							,__lowerCAmelCase:						int=3							,__lowerCAmelCase:						str=32							,__lowerCAmelCase:						Dict=0.1							,__lowerCAmelCase:						Optional[Any]=0.1							,__lowerCAmelCase:						Optional[Any]=0.1							,__lowerCAmelCase:						List[str]=0.02							,__lowerCAmelCase:						int=True							,__lowerCAmelCase:						int=True							,__lowerCAmelCase:						str=10							,__lowerCAmelCase:						List[str]=None							,):







     '''simple docstring'''







     _lowerCamelCase   :				Optional[int]							=     parent
     _lowerCamelCase   :				Dict							=     batch_size
     _lowerCamelCase   :				int							=     image_size
     _lowerCamelCase   :				int							=     patch_size
     _lowerCamelCase   :				Dict							=     num_channels
     _lowerCamelCase   :				Optional[Any]							=     last_hidden_size
     _lowerCamelCase   :				Tuple							=     num_attention_heads
     _lowerCamelCase   :				Any							=     hidden_act
     _lowerCamelCase   :				Union[str, Any]							=     conv_kernel_size
     _lowerCamelCase   :				Any							=     output_stride
     _lowerCamelCase   :				Any							=     hidden_dropout_prob
     _lowerCamelCase   :				Optional[int]							=     attention_probs_dropout_prob
     _lowerCamelCase   :				Optional[Any]							=     classifier_dropout_prob
     _lowerCamelCase   :				Union[str, Any]							=     use_labels
     _lowerCamelCase   :				Dict							=     is_training
     _lowerCamelCase   :				int							=     num_labels
     _lowerCamelCase   :				str							=     initializer_range
     _lowerCamelCase   :				Optional[int]							=     scope


  def 							_lowercase					(			self:						int    ):







     '''simple docstring'''







     _lowerCamelCase   :				int							=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )

     _lowerCamelCase   :				Dict							=     None
     _lowerCamelCase   :				Union[str, Any]							=     None
     if self.use_labels:
        _lowerCamelCase   :				Dict							=     ids_tensor([self.batch_size]							,self.num_labels    )
        _lowerCamelCase   :				Tuple							=     ids_tensor([self.batch_size, self.image_size, self.image_size]							,self.num_labels    )

     _lowerCamelCase   :				Dict							=     self.get_config()

     return config, pixel_values, labels, pixel_labels


  def 							_lowercase					(			self:						str    ):







     '''simple docstring'''







     return MobileViTConfig(
         image_size=self.image_size							,patch_size=self.patch_size							,num_channels=self.num_channels							,num_attention_heads=self.num_attention_heads							,hidden_act=self.hidden_act							,conv_kernel_size=self.conv_kernel_size							,output_stride=self.output_stride							,hidden_dropout_prob=self.hidden_dropout_prob							,attention_probs_dropout_prob=self.attention_probs_dropout_prob							,classifier_dropout_prob=self.classifier_dropout_prob							,initializer_range=self.initializer_range							,)


  def 							_lowercase					(			self:						Optional[int]							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						Optional[Any]							,__lowerCAmelCase:						int							,__lowerCAmelCase:						int    ):







     '''simple docstring'''







     _lowerCamelCase   :				Optional[int]							=     MobileViTModel(config=__lowerCAmelCase    )
     model.to(__lowerCAmelCase    )
     model.eval()
     _lowerCamelCase   :				Dict							=     model(__lowerCAmelCase    )
     self.parent.assertEqual(
         result.last_hidden_state.shape							,(
             self.batch_size,
             self.last_hidden_size,
             self.image_size // self.output_stride,
             self.image_size // self.output_stride,
         )							,)


  def 							_lowercase					(			self:						Union[str, Any]							,__lowerCAmelCase:						Dict							,__lowerCAmelCase:						Optional[int]							,__lowerCAmelCase:						List[Any]							,__lowerCAmelCase:						str    ):







     '''simple docstring'''







     _lowerCamelCase   :				List[Any]							=     self.num_labels
     _lowerCamelCase   :				str							=     MobileViTForImageClassification(__lowerCAmelCase    )
     model.to(__lowerCAmelCase    )
     model.eval()
     _lowerCamelCase   :				List[str]							=     model(__lowerCAmelCase							,labels=__lowerCAmelCase    )
     self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.num_labels)    )


  def 							_lowercase					(			self:						List[str]							,__lowerCAmelCase:						int							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						Union[str, Any]							,__lowerCAmelCase:						Optional[Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Dict							=     self.num_labels
     _lowerCamelCase   :				Tuple							=     MobileViTForSemanticSegmentation(__lowerCAmelCase    )
     model.to(__lowerCAmelCase    )
     model.eval()
     _lowerCamelCase   :				Optional[Any]							=     model(__lowerCAmelCase    )
     self.parent.assertEqual(
         result.logits.shape							,(
             self.batch_size,
             self.num_labels,
             self.image_size // self.output_stride,
             self.image_size // self.output_stride,
         )							,)
     _lowerCamelCase   :				Tuple							=     model(__lowerCAmelCase							,labels=__lowerCAmelCase    )
     self.parent.assertEqual(
         result.logits.shape							,(
             self.batch_size,
             self.num_labels,
             self.image_size // self.output_stride,
             self.image_size // self.output_stride,
         )							,)






  def 							_lowercase					(			self:						str    ):







     '''simple docstring'''







     _lowerCamelCase   :				List[str]							=     self.prepare_config_and_inputs()
     _lowerCamelCase,					_lowerCamelCase,					_lowerCamelCase,					_lowerCamelCase   :				int							=     config_and_inputs
     _lowerCamelCase   :				Optional[int]							=     {"pixel_values": pixel_values}
     return config, inputs_dict




@require_torch
class 							A_      (       _a     ,	_a     ,	unittest.TestCase ):
  lowerCAmelCase__      			=	(
      (MobileViTModel, MobileViTForImageClassification, MobileViTForSemanticSegmentation)
      if is_torch_available()
      else ()
  )
  lowerCAmelCase__      			=	(
      {
          'feature-extraction': MobileViTModel,
          'image-classification': MobileViTForImageClassification,
          'image-segmentation': MobileViTForSemanticSegmentation,
      }
      if is_torch_available()
      else {}
  )

  lowerCAmelCase__      			=	False
  lowerCAmelCase__      			=	False
  lowerCAmelCase__      			=	False
  lowerCAmelCase__      			=	False


  def 							_lowercase					(			self:						Any    ):







     '''simple docstring'''







     _lowerCamelCase   :				Optional[Any]							=     MobileViTModelTester(self    )
     _lowerCamelCase   :				Optional[int]							=     MobileViTConfigTester(self							,config_class=__lowerCAmelCase							,has_text_modality=__lowerCAmelCase    )


  def 							_lowercase					(			self:						Optional[Any]    ):







     '''simple docstring'''







     self.config_tester.run_common_tests()


  @unittest.skip(reason="MobileViT does not use inputs_embeds"    )
  def 							_lowercase					(			self:						Union[str, Any]    ):







     '''simple docstring'''







     pass


  @unittest.skip(reason="MobileViT does not support input and output embeddings"    )
  def 							_lowercase					(			self:						Any    ):







     '''simple docstring'''







     pass


  @unittest.skip(reason="MobileViT does not output attentions"    )
  def 							_lowercase					(			self:						List[str]    ):







     '''simple docstring'''







     pass


  def 							_lowercase					(			self:						int    ):







     '''simple docstring'''







     _lowerCamelCase,					_lowerCamelCase   :				Union[str, Any]							=     self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
        _lowerCamelCase   :				Any							=     model_class(__lowerCAmelCase    )
        _lowerCamelCase   :				Optional[Any]							=     inspect.signature(model.forward    )
        # signature.parameters is an OrderedDict => so arg_names order is deterministic
        _lowerCamelCase   :				List[str]							=     [*signature.parameters.keys()]

        _lowerCamelCase   :				Optional[Any]							=     ["pixel_values"]
        self.assertListEqual(arg_names[:1]							,__lowerCAmelCase    )


  @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."    )
  def 							_lowercase					(			self:						List[Any]    ):







     '''simple docstring'''







     pass


  def 							_lowercase					(			self:						Optional[Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Tuple							=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*__lowerCAmelCase    )


  def 							_lowercase					(			self:						Tuple    ):







     '''simple docstring'''







     def check_hidden_states_output(__lowerCAmelCase:						int							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						int    ):
        _lowerCamelCase   :				str							=     model_class(__lowerCAmelCase    )
        model.to(__lowerCAmelCase    )
        model.eval()

        with torch.no_grad():
           _lowerCamelCase   :				int							=     model(**self._prepare_for_class(__lowerCAmelCase							,__lowerCAmelCase    )    )

        _lowerCamelCase   :				Dict							=     outputs.hidden_states

        _lowerCamelCase   :				Optional[Any]							=     5
        self.assertEqual(len(__lowerCAmelCase    )							,__lowerCAmelCase    )

        # MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
        # with the width and height being successively divided by 2.
        _lowerCamelCase   :				int							=     2
        for i in range(len(__lowerCAmelCase    )    ):
           self.assertListEqual(
               list(hidden_states[i].shape[-2:]    )							,[self.model_tester.image_size // divisor, self.model_tester.image_size // divisor]							,)
           divisor *= 2

        self.assertEqual(self.model_tester.output_stride							,divisor // 2    )

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

     for model_class in self.all_model_classes:
        _lowerCamelCase   :				Optional[Any]							=     True
        check_hidden_states_output(__lowerCAmelCase							,__lowerCAmelCase							,__lowerCAmelCase    )

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

        check_hidden_states_output(__lowerCAmelCase							,__lowerCAmelCase							,__lowerCAmelCase    )


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







     '''simple docstring'''







     _lowerCamelCase   :				int							=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_image_classification(*__lowerCAmelCase    )


  def 							_lowercase					(			self:						Optional[int]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Union[str, Any]							=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_semantic_segmentation(*__lowerCAmelCase    )






  @slow
  def 							_lowercase					(			self:						List[Any]    ):







     '''simple docstring'''







     for model_name in MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        _lowerCamelCase   :				Union[str, Any]							=     MobileViTModel.from_pretrained(__lowerCAmelCase    )
        self.assertIsNotNone(__lowerCAmelCase    )







def        lowerCamelCase_(		)    ->     str:
   '''simple docstring'''





   _lowerCamelCase   :				Union[str, Any]							=     Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"       )
   return image




@require_torch
@require_vision
class 							A_      (       unittest.TestCase ):


  @cached_property
  def 							_lowercase					(			self:						Any    ):







     '''simple docstring'''







     return MobileViTImageProcessor.from_pretrained("apple/mobilevit-xx-small"    ) if is_vision_available() else None


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







     '''simple docstring'''







     _lowerCamelCase   :				Tuple							=     MobileViTForImageClassification.from_pretrained("apple/mobilevit-xx-small"    ).to(__lowerCAmelCase    )

     _lowerCamelCase   :				int							=     self.default_image_processor
     _lowerCamelCase   :				Union[str, Any]							=     prepare_img()
     _lowerCamelCase   :				List[Any]							=     image_processor(images=__lowerCAmelCase							,return_tensors="pt"    ).to(__lowerCAmelCase    )

     # forward pass
     with torch.no_grad():
        _lowerCamelCase   :				Dict							=     model(**__lowerCAmelCase    )

     # verify the logits
     _lowerCamelCase   :				str							=     torch.Size((1, 1_000)    )
     self.assertEqual(outputs.logits.shape							,__lowerCAmelCase    )

     _lowerCamelCase   :				Any							=     torch.tensor([-1.93_64, -1.23_27, -0.46_53]    ).to(__lowerCAmelCase    )

     self.assertTrue(torch.allclose(outputs.logits[0, :3]							,__lowerCAmelCase							,atol=1e-4    )    )


  @slow
  def 							_lowercase					(			self:						Optional[Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				str							=     MobileViTForSemanticSegmentation.from_pretrained("apple/deeplabv3-mobilevit-xx-small"    )
     _lowerCamelCase   :				Any							=     model.to(__lowerCAmelCase    )

     _lowerCamelCase   :				Tuple							=     MobileViTImageProcessor.from_pretrained("apple/deeplabv3-mobilevit-xx-small"    )

     _lowerCamelCase   :				Any							=     prepare_img()
     _lowerCamelCase   :				int							=     image_processor(images=__lowerCAmelCase							,return_tensors="pt"    ).to(__lowerCAmelCase    )

     # forward pass
     with torch.no_grad():
        _lowerCamelCase   :				List[str]							=     model(**__lowerCAmelCase    )
     _lowerCamelCase   :				Optional[Any]							=     outputs.logits

     # verify the logits
     _lowerCamelCase   :				List[str]							=     torch.Size((1, 21, 32, 32)    )
     self.assertEqual(logits.shape							,__lowerCAmelCase    )

     _lowerCamelCase   :				Dict							=     torch.tensor(
         [
             [[6.97_13, 6.97_86, 7.24_22], [7.28_93, 7.28_25, 7.44_46], [7.65_80, 7.87_97, 7.94_20]],
             [[-10.68_69, -10.32_50, -10.34_71], [-10.42_28, -9.98_68, -9.71_32], [-11.04_05, -11.02_21, -10.73_18]],
             [[-3.30_89, -2.85_39, -2.67_40], [-3.27_06, -2.56_21, -2.51_08], [-3.25_34, -2.66_15, -2.66_51]],
         ]							,device=__lowerCAmelCase							,)

     self.assertTrue(torch.allclose(logits[0, :3, :3, :3]							,__lowerCAmelCase							,atol=1e-4    )    )






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







     '''simple docstring'''







     _lowerCamelCase   :				str							=     MobileViTForSemanticSegmentation.from_pretrained("apple/deeplabv3-mobilevit-xx-small"    )
     _lowerCamelCase   :				Optional[Any]							=     model.to(__lowerCAmelCase    )

     _lowerCamelCase   :				Dict							=     MobileViTImageProcessor.from_pretrained("apple/deeplabv3-mobilevit-xx-small"    )

     _lowerCamelCase   :				int							=     prepare_img()
     _lowerCamelCase   :				Any							=     image_processor(images=__lowerCAmelCase							,return_tensors="pt"    ).to(__lowerCAmelCase    )

     # forward pass
     with torch.no_grad():
        _lowerCamelCase   :				Optional[int]							=     model(**__lowerCAmelCase    )

     _lowerCamelCase   :				Optional[Any]							=     outputs.logits.detach().cpu()

     _lowerCamelCase   :				Dict							=     image_processor.post_process_semantic_segmentation(outputs=__lowerCAmelCase							,target_sizes=[(50, 60)]    )
     _lowerCamelCase   :				Optional[Any]							=     torch.Size((50, 60)    )
     self.assertEqual(segmentation[0].shape							,__lowerCAmelCase    )

     _lowerCamelCase   :				Any							=     image_processor.post_process_semantic_segmentation(outputs=__lowerCAmelCase    )
     _lowerCamelCase   :				List[str]							=     torch.Size((32, 32)    )
     self.assertEqual(segmentation[0].shape							,__lowerCAmelCase    )

def 							SCREAMING_SNAKE_CASE_	(					UpperCAmelCase_	:     int = 1_0_0_0				)			->						int:
       SCREAMING_SNAKE_CASE_							:				int		=2**power
       SCREAMING_SNAKE_CASE_							:				Tuple		=0
       while n:
              SCREAMING_SNAKE_CASE_	,     SCREAMING_SNAKE_CASE_							:				Union[str, Any]		=r + n % 1_0, n // 1_0
       return r


if __name__ == "__main__":
 print(solution(int(str(input()).strip())))
