





'''simple docstring'''



import inspect
import unittest

import numpy as np

from transformers import BeitConfig
from transformers.testing_utils import require_flax, require_vision, slow
from transformers.utils import cached_property, is_flax_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor


if is_flax_available():
	import jax

	from transformers import FlaxBeitForImageClassification, FlaxBeitForMaskedImageModeling, FlaxBeitModel

if is_vision_available():
	from PIL import Image

	from transformers import BeitImageProcessor






class 							__lowercase    ( unittest.TestCase  ):







	'''simple docstring'''

	def __init__(self       ,_lowerCamelCase       ,_lowerCamelCase=100       ,_lowerCamelCase=13       ,_lowerCamelCase=30       ,_lowerCamelCase=2       ,_lowerCamelCase=3       ,_lowerCamelCase=True       ,_lowerCamelCase=True       ,_lowerCamelCase=32       ,_lowerCamelCase=5       ,_lowerCamelCase=4       ,_lowerCamelCase=37       ,_lowerCamelCase="gelu"       ,_lowerCamelCase=0.1       ,_lowerCamelCase=0.1       ,_lowerCamelCase=10       ,_lowerCamelCase=0.0_2       ,_lowerCamelCase=3       ,)							->							List[str]:







				'''simple docstring'''





				__lowercase			  =							parent
				__lowercase			  =							vocab_size
				__lowercase			  =							batch_size
				__lowercase			  =							image_size
				__lowercase			  =							patch_size
				__lowercase			  =							num_channels
				__lowercase			  =							is_training
				__lowercase			  =							use_labels
				__lowercase			  =							hidden_size
				__lowercase			  =							num_hidden_layers
				__lowercase			  =							num_attention_heads
				__lowercase			  =							intermediate_size
				__lowercase			  =							hidden_act
				__lowercase			  =							hidden_dropout_prob
				__lowercase			  =							attention_probs_dropout_prob
				__lowercase			  =							type_sequence_label_size
				__lowercase			  =							initializer_range

				# in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
				__lowercase			  =							(image_size // patch_size) ** 2
				__lowercase			  =							num_patches + 1


	def   _UpperCAmelCase       (self	)							->							Dict:







				'''simple docstring'''





				__lowercase			  =							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

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

				__lowercase			  =							BeitConfig(
				    vocab_size=self.vocab_size       ,image_size=self.image_size       ,patch_size=self.patch_size       ,num_channels=self.num_channels       ,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       ,is_decoder=_lowerCamelCase       ,initializer_range=self.initializer_range       ,)

				return config, pixel_values, labels


	def   _UpperCAmelCase       (self       ,_lowerCamelCase       ,_lowerCamelCase       ,_lowerCamelCase	)							->							Dict:







				'''simple docstring'''





				__lowercase			  =							FlaxBeitModel(config=_lowerCamelCase	)
				__lowercase			  =							model(_lowerCamelCase	)
				self.parent.assertEqual(result.last_hidden_state.shape       ,(self.batch_size, self.seq_length, self.hidden_size)	)


	def   _UpperCAmelCase       (self       ,_lowerCamelCase       ,_lowerCamelCase       ,_lowerCamelCase	)							->							List[str]:







				'''simple docstring'''





				__lowercase			  =							FlaxBeitForMaskedImageModeling(config=_lowerCamelCase	)
				__lowercase			  =							model(_lowerCamelCase	)
				self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.seq_length - 1, self.vocab_size)	)


	def   _UpperCAmelCase       (self       ,_lowerCamelCase       ,_lowerCamelCase       ,_lowerCamelCase	)							->							int:







				'''simple docstring'''





				__lowercase			  =							self.type_sequence_label_size
				__lowercase			  =							FlaxBeitForImageClassification(config=_lowerCamelCase	)
				__lowercase			  =							model(_lowerCamelCase	)
				self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.type_sequence_label_size)	)

				# test greyscale images
				__lowercase			  =							1
				__lowercase			  =							FlaxBeitForImageClassification(_lowerCamelCase	)

				__lowercase			  =							floats_tensor([self.batch_size, 1, self.image_size, self.image_size]	)
				__lowercase			  =							model(_lowerCamelCase	)


	def   _UpperCAmelCase       (self	)							->							int:







				'''simple docstring'''





				__lowercase			  =							self.prepare_config_and_inputs()
				(
				    (
				    __lowercase
				)  ,						(
				    __lowercase
				)  ,						(
				    __lowercase
				)  ,						
				)			  =							config_and_inputs
				__lowercase			  =							{'''pixel_values''': pixel_values}
				return config, inputs_dict






@require_flax
class 							__lowercase    ( lowerCAmelCase__	, unittest.TestCase  ):







	'''simple docstring'''

	a      :			str     =    (
	    (FlaxBeitModel, FlaxBeitForImageClassification, FlaxBeitForMaskedImageModeling) if is_flax_available() else ()
	)


	def   _UpperCAmelCase       (self	)							->							None:







				'''simple docstring'''





				__lowercase			  =							FlaxBeitModelTester(self	)
				__lowercase			  =							ConfigTester(self       ,config_class=_lowerCamelCase       ,has_text_modality=_lowerCamelCase       ,hidden_size=37	)


	def   _UpperCAmelCase       (self	)							->							Union[str, Any]:







				'''simple docstring'''





				self.config_tester.run_common_tests()


	def   _UpperCAmelCase       (self	)							->							Tuple:







				'''simple docstring'''





				__lowercase  ,						__lowercase			  =							self.model_tester.prepare_config_and_inputs_for_common()

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

							__lowercase			  =							['''pixel_values''']
							self.assertListEqual(arg_names[:1]       ,_lowerCamelCase	)


	def   _UpperCAmelCase       (self	)							->							Union[str, Any]:







				'''simple docstring'''





				__lowercase  ,						__lowercase			  =							self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
							with self.subTest(model_class.__name__	):
										__lowercase			  =							self._prepare_for_class(_lowerCamelCase       ,_lowerCamelCase	)
										__lowercase			  =							model_class(_lowerCamelCase	)

										@jax.jit
										def model_jitted(_lowerCamelCase       ,**_lowerCamelCase	):
													return model(pixel_values=_lowerCamelCase       ,**_lowerCamelCase	)

										with self.subTest('''JIT Enabled'''	):
													__lowercase			  =							model_jitted(**_lowerCamelCase	).to_tuple()

										with self.subTest('''JIT Disabled'''	):
													with jax.disable_jit():
																__lowercase			  =							model_jitted(**_lowerCamelCase	).to_tuple()

										self.assertEqual(len(_lowerCamelCase	)       ,len(_lowerCamelCase	)	)
										for jitted_output, output in zip(_lowerCamelCase       ,_lowerCamelCase	):
													self.assertEqual(jitted_output.shape       ,output.shape	)


	def   _UpperCAmelCase       (self	)							->							Any:







				'''simple docstring'''





				__lowercase			  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*_lowerCamelCase	)


	def   _UpperCAmelCase       (self	)							->							Union[str, Any]:







				'''simple docstring'''





				__lowercase			  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_lm(*_lowerCamelCase	)


	def   _UpperCAmelCase       (self	)							->							Any:







				'''simple docstring'''





				__lowercase			  =							self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*_lowerCamelCase	)


	@slow
	def   _UpperCAmelCase       (self	)							->							Any:







				'''simple docstring'''





				for model_class_name in self.all_model_classes:
							__lowercase			  =							model_class_name.from_pretrained('''microsoft/beit-base-patch16-224'''	)
							__lowercase			  =							model(np.ones((1, 3, 224, 224)	)	)
							self.assertIsNotNone(_lowerCamelCase	)





def 				_lowerCAmelCase  (			):
			__lowercase			  =							Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''			)
			return image






@require_vision
@require_flax
class 							__lowercase    ( unittest.TestCase  ):







	'''simple docstring'''

	@cached_property
	def   _UpperCAmelCase       (self	)							->							List[str]:







				'''simple docstring'''





				return BeitImageProcessor.from_pretrained('''microsoft/beit-base-patch16-224'''	) if is_vision_available() else None


	@slow
	def   _UpperCAmelCase       (self	)							->							Dict:







				'''simple docstring'''





				__lowercase			  =							FlaxBeitForMaskedImageModeling.from_pretrained('''microsoft/beit-base-patch16-224-pt22k'''	)

				__lowercase			  =							self.default_image_processor
				__lowercase			  =							prepare_img()
				__lowercase			  =							image_processor(images=_lowerCamelCase       ,return_tensors='''np'''	).pixel_values

				# prepare bool_masked_pos
				__lowercase			  =							np.ones((1, 196)       ,dtype=_lowerCamelCase	)

				# forward pass
				__lowercase			  =							model(pixel_values=_lowerCamelCase       ,bool_masked_pos=_lowerCamelCase	)
				__lowercase			  =							outputs.logits

				# verify the logits
				__lowercase			  =							(1, 196, 8192)
				self.assertEqual(logits.shape       ,_lowerCamelCase	)

				__lowercase			  =							np.array(
				    [[-3.2_4_3_7, 0.5_0_7_2, -1_3.9_1_7_4], [-3.2_4_5_6, 0.4_9_4_8, -1_3.9_4_0_1], [-3.2_0_3_3, 0.5_1_2_1, -1_3.8_5_5_0]]	)

				self.assertTrue(np.allclose(logits[bool_masked_pos][:3, :3]       ,_lowerCamelCase       ,atol=1E-2	)	)


	@slow
	def   _UpperCAmelCase       (self	)							->							List[Any]:







				'''simple docstring'''





				__lowercase			  =							FlaxBeitForImageClassification.from_pretrained('''microsoft/beit-base-patch16-224'''	)

				__lowercase			  =							self.default_image_processor
				__lowercase			  =							prepare_img()
				__lowercase			  =							image_processor(images=_lowerCamelCase       ,return_tensors='''np'''	)

				# forward pass
				__lowercase			  =							model(**_lowerCamelCase	)
				__lowercase			  =							outputs.logits

				# verify the logits
				__lowercase			  =							(1, 1000)
				self.assertEqual(logits.shape       ,_lowerCamelCase	)

				__lowercase			  =							np.array([-1.2_3_8_5, -1.0_9_8_7, -1.0_1_0_8]	)

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

				__lowercase			  =							281
				self.assertEqual(logits.argmax(-1	).item()       ,_lowerCamelCase	)


	@slow
	def   _UpperCAmelCase       (self	)							->							int:







				'''simple docstring'''





				__lowercase			  =							FlaxBeitForImageClassification.from_pretrained('''microsoft/beit-large-patch16-224-pt22k-ft22k'''	)

				__lowercase			  =							self.default_image_processor
				__lowercase			  =							prepare_img()
				__lowercase			  =							image_processor(images=_lowerCamelCase       ,return_tensors='''np'''	)

				# forward pass
				__lowercase			  =							model(**_lowerCamelCase	)
				__lowercase			  =							outputs.logits

				# verify the logits
				__lowercase			  =							(1, 21841)
				self.assertEqual(logits.shape       ,_lowerCamelCase	)

				__lowercase			  =							np.array([1.6_8_8_1, -0.2_7_8_7, 0.5_9_0_1]	)

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

				__lowercase			  =							2396
				self.assertEqual(logits.argmax(-1	).item()       ,_lowerCamelCase	)












'''simple docstring'''



from math import sqrt




def 				_lowerCAmelCase  (			lowerCamelCase_     :					int			):
			__lowercase			  =							0
			for i in range(1						,    int(sqrt(lowerCamelCase_			) + 1			)			):
						if n % i == 0 and i != sqrt(lowerCamelCase_			):
									total += i + n // i
						elif i == sqrt(lowerCamelCase_			):
									total += i
			return total - n




def 				_lowerCAmelCase  (			lowerCamelCase_     :					int = 1_0_0_0_0			):
			__lowercase			  =							sum(
			    i
			    for i in range(1						,    lowerCamelCase_			)
			    if sum_of_divisors(sum_of_divisors(lowerCamelCase_			)			) == i and sum_of_divisors(lowerCamelCase_			) != i			)
			return total


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





