



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				(   _lowerCAmelCase					):

			def      __snake_case       (self					)       ->   str:
						UpperCAmelCase_:		Optional[int]							      =     self.config_class(**self.inputs_dict					)
						self.parent.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,   """hidden_sizes"""					)					)
						self.parent.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,   """neck_hidden_sizes"""					)					)
						self.parent.assertTrue(hasattr(SCREAMING_SNAKE_CASE_,   """num_attention_heads"""					)					)







class 				_a				:

			def __init__(self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_=13,   SCREAMING_SNAKE_CASE_=32,   SCREAMING_SNAKE_CASE_=2,   SCREAMING_SNAKE_CASE_=3,   SCREAMING_SNAKE_CASE_=640,   SCREAMING_SNAKE_CASE_=4,   SCREAMING_SNAKE_CASE_="silu",   SCREAMING_SNAKE_CASE_=3,   SCREAMING_SNAKE_CASE_=32,   SCREAMING_SNAKE_CASE_=0.1,   SCREAMING_SNAKE_CASE_=0.1,   SCREAMING_SNAKE_CASE_=0.1,   SCREAMING_SNAKE_CASE_=0.0_2,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=10,   SCREAMING_SNAKE_CASE_=None,   )       ->   List[Any]:
						UpperCAmelCase_:		str							      =     parent
						UpperCAmelCase_:		Union[str, Any]							      =     batch_size
						UpperCAmelCase_:		List[str]							      =     image_size
						UpperCAmelCase_:		Union[str, Any]							      =     patch_size
						UpperCAmelCase_:		str							      =     num_channels
						UpperCAmelCase_:		List[Any]							      =     last_hidden_size
						UpperCAmelCase_:		Optional[Any]							      =     num_attention_heads
						UpperCAmelCase_:		Optional[int]							      =     hidden_act
						UpperCAmelCase_:		List[str]							      =     conv_kernel_size
						UpperCAmelCase_:		Union[str, Any]							      =     output_stride
						UpperCAmelCase_:		str							      =     hidden_dropout_prob
						UpperCAmelCase_:		str							      =     attention_probs_dropout_prob
						UpperCAmelCase_:		Optional[int]							      =     classifier_dropout_prob
						UpperCAmelCase_:		Optional[int]							      =     use_labels
						UpperCAmelCase_:		List[str]							      =     is_training
						UpperCAmelCase_:		str							      =     num_labels
						UpperCAmelCase_:		List[Any]							      =     initializer_range
						UpperCAmelCase_:		Union[str, Any]							      =     scope

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		int							      =     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

						UpperCAmelCase_:		int							      =     None
						UpperCAmelCase_:		Tuple							      =     None
						if self.use_labels:
									UpperCAmelCase_:		Optional[Any]							      =     ids_tensor([self.batch_size],   self.num_labels					)
									UpperCAmelCase_:		Optional[Any]							      =     ids_tensor([self.batch_size, self.image_size, self.image_size],   self.num_labels					)

						UpperCAmelCase_:		List[Any]							      =     self.get_config()

						return config, pixel_values, labels, pixel_labels

			def      __snake_case       (self					)       ->   Optional[Any]:
						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      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   List[str]:
						UpperCAmelCase_:		int							      =     MobileViTModel(config=SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		List[str]							      =     model(SCREAMING_SNAKE_CASE_					)
						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      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   Dict:
						UpperCAmelCase_:		Dict							      =     self.num_labels
						UpperCAmelCase_:		int							      =     MobileViTForImageClassification(SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		int							      =     model(SCREAMING_SNAKE_CASE_,   labels=SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.num_labels)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   Union[str, Any]:
						UpperCAmelCase_:		List[str]							      =     self.num_labels
						UpperCAmelCase_:		int							      =     MobileViTForSemanticSegmentation(SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		int							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(
						    result.logits.shape,   (
						        self.batch_size,
						        self.num_labels,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    ),   )
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_,   labels=SCREAMING_SNAKE_CASE_					)
						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      __snake_case       (self					)       ->   Optional[Any]:
						UpperCAmelCase_:		Dict							      =     self.prepare_config_and_inputs()
						UpperCAmelCase_      ,							UpperCAmelCase_      ,							UpperCAmelCase_      ,							UpperCAmelCase_:		Union[str, Any]							      =     config_and_inputs
						UpperCAmelCase_:		List[Any]							      =     {"""pixel_values""": pixel_values}
						return config, inputs_dict







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

			A      		=	False
			A      		=	False
			A      		=	False
			A      		=	False

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Union[str, Any]							      =     MobileViTModelTester(self					)
						UpperCAmelCase_:		Optional[Any]							      =     MobileViTConfigTester(self,   config_class=SCREAMING_SNAKE_CASE_,   has_text_modality=SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   int:
						self.config_tester.run_common_tests()

			@unittest.skip(reason="""MobileViT does not use inputs_embeds"""					)
			def      __snake_case       (self					)       ->   Dict:
						pass

			@unittest.skip(reason="""MobileViT does not support input and output embeddings"""					)
			def      __snake_case       (self					)       ->   List[str]:
						pass

			@unittest.skip(reason="""MobileViT does not output attentions"""					)
			def      __snake_case       (self					)       ->   Any:
						pass

			def      __snake_case       (self					)       ->   Any:
						UpperCAmelCase_      ,							UpperCAmelCase_:		Optional[Any]							      =     self.model_tester.prepare_config_and_inputs_for_common()

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

									UpperCAmelCase_:		str							      =     ["""pixel_values"""]
									self.assertListEqual(arg_names[:1],   SCREAMING_SNAKE_CASE_					)

			@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""					)
			def      __snake_case       (self					)       ->   Any:
						pass

			def      __snake_case       (self					)       ->   Dict:
						UpperCAmelCase_:		Any							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Dict:
						def check_hidden_states_output(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					):
									UpperCAmelCase_:		List[str]							      =     model_class(SCREAMING_SNAKE_CASE_					)
									model.to(SCREAMING_SNAKE_CASE_					)
									model.eval()

									with torch.no_grad():
												UpperCAmelCase_:		List[Any]							      =     model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)					)

									UpperCAmelCase_:		Dict							      =     outputs.hidden_states

									UpperCAmelCase_:		int							      =     5
									self.assertEqual(len(SCREAMING_SNAKE_CASE_					),   SCREAMING_SNAKE_CASE_					)

									# MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
									# with the width and height being successively divided by 2.
									UpperCAmelCase_:		Union[str, Any]							      =     2
									for i in range(len(SCREAMING_SNAKE_CASE_					)					):
												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					)

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

						for model_class in self.all_model_classes:
									UpperCAmelCase_:		Dict							      =     True
									check_hidden_states_output(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)

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

									check_hidden_states_output(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Optional[Any]:
						UpperCAmelCase_:		Any							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Any							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_semantic_segmentation(*SCREAMING_SNAKE_CASE_					)

			@slow
			def      __snake_case       (self					)       ->   List[str]:
						for model_name in MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									UpperCAmelCase_:		List[Any]							      =     MobileViTModel.from_pretrained(SCREAMING_SNAKE_CASE_					)
									self.assertIsNotNone(SCREAMING_SNAKE_CASE_					)







def  lowerCAmelCase_	():





			"""simple docstring"""


			UpperCAmelCase_:		Optional[Any]							      =     Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
			return image







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

			@cached_property
			def      __snake_case       (self					)       ->   List[str]:
						return MobileViTImageProcessor.from_pretrained("""apple/mobilevit-xx-small"""					) if is_vision_available() else None

			@slow
			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		List[Any]							      =     MobileViTForImageClassification.from_pretrained("""apple/mobilevit-xx-small"""					).to(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		str							      =     self.default_image_processor
						UpperCAmelCase_:		Dict							      =     prepare_img()
						UpperCAmelCase_:		List[str]							      =     image_processor(images=SCREAMING_SNAKE_CASE_,   return_tensors="""pt"""					).to(SCREAMING_SNAKE_CASE_					)

						# forward pass
						with torch.no_grad():
									UpperCAmelCase_:		Union[str, Any]							      =     model(**SCREAMING_SNAKE_CASE_					)

						# verify the logits
						UpperCAmelCase_:		Dict							      =     torch.Size((1, 1000)					)
						self.assertEqual(outputs.logits.shape,   SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		str							      =     torch.tensor([-1.9_3_6_4, -1.2_3_2_7, -0.4_6_5_3]					).to(SCREAMING_SNAKE_CASE_					)

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

			@slow
			def      __snake_case       (self					)       ->   Any:
						UpperCAmelCase_:		List[Any]							      =     MobileViTForSemanticSegmentation.from_pretrained("""apple/deeplabv3-mobilevit-xx-small"""					)
						UpperCAmelCase_:		str							      =     model.to(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		List[str]							      =     MobileViTImageProcessor.from_pretrained("""apple/deeplabv3-mobilevit-xx-small"""					)

						UpperCAmelCase_:		Tuple							      =     prepare_img()
						UpperCAmelCase_:		Tuple							      =     image_processor(images=SCREAMING_SNAKE_CASE_,   return_tensors="""pt"""					).to(SCREAMING_SNAKE_CASE_					)

						# forward pass
						with torch.no_grad():
									UpperCAmelCase_:		Union[str, Any]							      =     model(**SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		str							      =     outputs.logits

						# verify the logits
						UpperCAmelCase_:		int							      =     torch.Size((1, 21, 32, 32)					)
						self.assertEqual(logits.shape,   SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		List[str]							      =     torch.tensor(
						    [
						        [[6.9_7_1_3, 6.9_7_8_6, 7.2_4_2_2], [7.2_8_9_3, 7.2_8_2_5, 7.4_4_4_6], [7.6_5_8_0, 7.8_7_9_7, 7.9_4_2_0]],
						        [[-1_0.6_8_6_9, -1_0.3_2_5_0, -1_0.3_4_7_1], [-1_0.4_2_2_8, -9.9_8_6_8, -9.7_1_3_2], [-1_1.0_4_0_5, -1_1.0_2_2_1, -1_0.7_3_1_8]],
						        [[-3.3_0_8_9, -2.8_5_3_9, -2.6_7_4_0], [-3.2_7_0_6, -2.5_6_2_1, -2.5_1_0_8], [-3.2_5_3_4, -2.6_6_1_5, -2.6_6_5_1]],
						    ],   device=SCREAMING_SNAKE_CASE_,   )

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

			@slow
			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		int							      =     MobileViTForSemanticSegmentation.from_pretrained("""apple/deeplabv3-mobilevit-xx-small"""					)
						UpperCAmelCase_:		str							      =     model.to(SCREAMING_SNAKE_CASE_					)

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

						UpperCAmelCase_:		Dict							      =     prepare_img()
						UpperCAmelCase_:		List[Any]							      =     image_processor(images=SCREAMING_SNAKE_CASE_,   return_tensors="""pt"""					).to(SCREAMING_SNAKE_CASE_					)

						# forward pass
						with torch.no_grad():
									UpperCAmelCase_:		int							      =     model(**SCREAMING_SNAKE_CASE_					)

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

						UpperCAmelCase_:		Any							      =     image_processor.post_process_semantic_segmentation(outputs=SCREAMING_SNAKE_CASE_,   target_sizes=[(50, 60)]					)
						UpperCAmelCase_:		List[str]							      =     torch.Size((50, 60)					)
						self.assertEqual(segmentation[0].shape,   SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		List[Any]							      =     image_processor.post_process_semantic_segmentation(outputs=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Dict							      =     torch.Size((32, 32)					)
						self.assertEqual(segmentation[0].shape,   SCREAMING_SNAKE_CASE_					)











from __future__ import annotations







def  lowerCAmelCase_	(lowerCAmelCase__:		int | str  ):





			"""simple docstring"""


			UpperCAmelCase_:		Optional[int]							      =     str(lowerCAmelCase__  )
			return n == n[::-1]







def  lowerCAmelCase_	(lowerCAmelCase__:		int = 1_0_0_0_0_0_0  ):





			"""simple docstring"""


			UpperCAmelCase_:		int							      =     0

			for i in range(1		,						lowerCAmelCase__  ):
						if is_palindrome(lowerCAmelCase__  ) and is_palindrome(bin(lowerCAmelCase__  ).split("""b"""  )[1]  ):
									total += i
			return total


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






