



'''simple docstring'''
import inspect
import math
import tempfile
import unittest

import numpy as np

from transformers import ViTMAEConfig
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 torch import nn

					from transformers import ViTMAEForPreTraining, ViTMAEModel
					from transformers.models.vit.modeling_vit import VIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import ViTImageProcessor






class 							lowercase__	:





	def __init__( self					:				Any ,lowerCamelCase__					:				Union[str, Any] ,lowerCamelCase__					:				List[str]=13 ,lowerCamelCase__					:				Union[str, Any]=30 ,lowerCamelCase__					:				Dict=2 ,lowerCamelCase__					:				int=3 ,lowerCamelCase__					:				Tuple=True ,lowerCamelCase__					:				Any=True ,lowerCamelCase__					:				Optional[Any]=32 ,lowerCamelCase__					:				List[str]=5 ,lowerCamelCase__					:				Optional[Any]=4 ,lowerCamelCase__					:				Optional[int]=37 ,lowerCamelCase__					:				Dict="gelu" ,lowerCamelCase__					:				List[Any]=0.1 ,lowerCamelCase__					:				Dict=0.1 ,lowerCamelCase__					:				Tuple=10 ,lowerCamelCase__					:				str=0.0_2 ,lowerCamelCase__					:				List[Any]=3 ,lowerCamelCase__					:				int=0.6 ,lowerCamelCase__					:				Tuple=None ,):







							'''simple docstring'''
							_UpperCamelCase					:		Dict 				=   parent
							_UpperCamelCase					:		Tuple 				=   batch_size
							_UpperCamelCase					:		Optional[int] 				=   image_size
							_UpperCamelCase					:		Tuple 				=   patch_size
							_UpperCamelCase					:		Optional[Any] 				=   num_channels
							_UpperCamelCase					:		int 				=   is_training
							_UpperCamelCase					:		int 				=   use_labels
							_UpperCamelCase					:		Optional[Any] 				=   hidden_size
							_UpperCamelCase					:		Any 				=   num_hidden_layers
							_UpperCamelCase					:		int 				=   num_attention_heads
							_UpperCamelCase					:		List[Any] 				=   intermediate_size
							_UpperCamelCase					:		List[Any] 				=   hidden_act
							_UpperCamelCase					:		Optional[Any] 				=   hidden_dropout_prob
							_UpperCamelCase					:		str 				=   attention_probs_dropout_prob
							_UpperCamelCase					:		int 				=   type_sequence_label_size
							_UpperCamelCase					:		str 				=   initializer_range
							_UpperCamelCase					:		List[Any] 				=   mask_ratio
							_UpperCamelCase					:		Tuple 				=   scope

							# in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
							# (we add 1 for the [CLS] token)
							_UpperCamelCase					:		Optional[int] 				=   (image_size // patch_size) ** 2
							_UpperCamelCase					:		int 				=   int(math.ceil((1 - mask_ratio) * (num_patches + 1) ) )





	def 	UpperCamelCase_  ( self					:				List[str] ):







							'''simple docstring'''
							_UpperCamelCase					:		Optional[int] 				=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )

							_UpperCamelCase					:		int 				=   None
							if self.use_labels:
													_UpperCamelCase					:		Optional[Any] 				=   ids_tensor([self.batch_size] ,self.type_sequence_label_size )

							_UpperCamelCase					:		Dict 				=   self.get_config()

							return config, pixel_values, labels





	def 	UpperCamelCase_  ( self					:				int ):







							'''simple docstring'''
							return ViTMAEConfig(
							    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 ,mask_ratio=self.mask_ratio ,)





	def 	UpperCamelCase_  ( self					:				Union[str, Any] ,lowerCamelCase__					:				List[str] ,lowerCamelCase__					:				Optional[int] ,lowerCamelCase__					:				Dict ):







							'''simple docstring'''
							_UpperCamelCase					:		Optional[int] 				=   ViTMAEModel(config=lowerCamelCase__ )
							model.to(lowerCamelCase__ )
							model.eval()
							_UpperCamelCase					:		Any 				=   model(lowerCamelCase__ )
							self.parent.assertEqual(result.last_hidden_state.shape ,(self.batch_size, self.seq_length, self.hidden_size) )





	def 	UpperCamelCase_  ( self					:				Tuple ,lowerCamelCase__					:				Optional[Any] ,lowerCamelCase__					:				str ,lowerCamelCase__					:				int ):







							'''simple docstring'''
							_UpperCamelCase					:		int 				=   ViTMAEForPreTraining(lowerCamelCase__ )
							model.to(lowerCamelCase__ )
							model.eval()
							_UpperCamelCase					:		List[str] 				=   model(lowerCamelCase__ )
							_UpperCamelCase					:		List[str] 				=   (self.image_size // self.patch_size) ** 2
							_UpperCamelCase					:		List[str] 				=   self.patch_size**2 * self.num_channels
							self.parent.assertEqual(result.logits.shape ,(self.batch_size, num_patches, expected_num_channels) )

							# test greyscale images
							_UpperCamelCase					:		int 				=   1
							_UpperCamelCase					:		Dict 				=   ViTMAEForPreTraining(lowerCamelCase__ )
							model.to(lowerCamelCase__ )
							model.eval()
							_UpperCamelCase					:		Optional[Any] 				=   floats_tensor([self.batch_size, 1, self.image_size, self.image_size] )
							_UpperCamelCase					:		str 				=   model(lowerCamelCase__ )
							_UpperCamelCase					:		Optional[int] 				=   self.patch_size**2
							self.parent.assertEqual(result.logits.shape ,(self.batch_size, num_patches, expected_num_channels) )





	def 	UpperCamelCase_  ( self					:				Dict ):







							'''simple docstring'''
							_UpperCamelCase					:		Optional[Any] 				=   self.prepare_config_and_inputs()
							_UpperCamelCase				,			_UpperCamelCase				,			_UpperCamelCase					:		Optional[int] 				=   config_and_inputs
							_UpperCamelCase					:		int 				=   {'pixel_values': pixel_values}
							return config, inputs_dict






@require_torch
class 							lowercase__	(							lowercase						,					lowercase						,					unittest.TestCase   ):
	lowercase__  				=			(ViTMAEModel, ViTMAEForPreTraining) if is_torch_available() else ()
	lowercase__  				=			{"""feature-extraction""": ViTMAEModel} if is_torch_available() else {}

	lowercase__  				=			False
	lowercase__  				=			False
	lowercase__  				=			False
	lowercase__  				=			False





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







							'''simple docstring'''
							_UpperCamelCase					:		List[str] 				=   ViTMAEModelTester(self )
							_UpperCamelCase					:		List[str] 				=   ConfigTester(self ,config_class=lowerCamelCase__ ,has_text_modality=lowerCamelCase__ ,hidden_size=37 )





	def 	UpperCamelCase_  ( self					:				List[Any] ):







							'''simple docstring'''
							self.config_tester.run_common_tests()





	@unittest.skip(reason='ViTMAE does not use inputs_embeds' )
	def 	UpperCamelCase_  ( self					:				str ):







							'''simple docstring'''
							pass





	def 	UpperCamelCase_  ( self					:				Dict ):







							'''simple docstring'''
							_UpperCamelCase				,			_UpperCamelCase					:		Tuple 				=   self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
													_UpperCamelCase					:		Any 				=   model_class(lowerCamelCase__ )
													self.assertIsInstance(model.get_input_embeddings() ,(nn.Module) )
													_UpperCamelCase					:		List[Any] 				=   model.get_output_embeddings()
													self.assertTrue(x is None or isinstance(lowerCamelCase__ ,nn.Linear ) )





	def 	UpperCamelCase_  ( self					:				Dict ):







							'''simple docstring'''
							_UpperCamelCase				,			_UpperCamelCase					:		Dict 				=   self.model_tester.prepare_config_and_inputs_for_common()

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

													_UpperCamelCase					:		List[Any] 				=   ['pixel_values']
													self.assertListEqual(arg_names[:1] ,lowerCamelCase__ )





	def 	UpperCamelCase_  ( self					:				str ):







							'''simple docstring'''
							_UpperCamelCase					:		List[Any] 				=   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowerCamelCase__ )





	def 	UpperCamelCase_  ( self					:				List[Any] ):







							'''simple docstring'''
							_UpperCamelCase					:		str 				=   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*lowerCamelCase__ )





	def 	UpperCamelCase_  ( self					:				Union[str, Any] ,lowerCamelCase__					:				Any ,lowerCamelCase__					:				List[Any] ,lowerCamelCase__					:				Optional[int] ):







							'''simple docstring'''
							# make masks reproducible
							np.random.seed(2 )

							_UpperCamelCase					:		int 				=   int((pt_model.config.image_size // pt_model.config.patch_size) ** 2 )
							_UpperCamelCase					:		List[Any] 				=   np.random.uniform(size=(self.model_tester.batch_size, num_patches) )
							_UpperCamelCase					:		Any 				=   torch.from_numpy(lowerCamelCase__ )

							# Add `noise` argument.
							# PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
							_UpperCamelCase					:		Optional[Any] 				=   pt_noise

							super().check_pt_tf_models(lowerCamelCase__ ,lowerCamelCase__ ,lowerCamelCase__ )





	def 	UpperCamelCase_  ( self					:				Tuple ):







							'''simple docstring'''
							_UpperCamelCase				,			_UpperCamelCase					:		Any 				=   self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
													_UpperCamelCase					:		Union[str, Any] 				=   model_class(lowerCamelCase__ )
													model.to(lowerCamelCase__ )
													model.eval()
													# make random mask reproducible
													torch.manual_seed(2 )
													with torch.no_grad():
																			_UpperCamelCase					:		Tuple 				=   model(**self._prepare_for_class(lowerCamelCase__ ,lowerCamelCase__ ) )

													_UpperCamelCase					:		Any 				=   outputs[0].cpu().numpy()
													_UpperCamelCase					:		List[str] 				=   0

													with tempfile.TemporaryDirectory() as tmpdirname:
																			model.save_pretrained(lowerCamelCase__ )
																			_UpperCamelCase					:		Any 				=   model_class.from_pretrained(lowerCamelCase__ )
																			model.to(lowerCamelCase__ )
																			# make random mask reproducible
																			torch.manual_seed(2 )
																			with torch.no_grad():
																									_UpperCamelCase					:		Optional[Any] 				=   model(**self._prepare_for_class(lowerCamelCase__ ,lowerCamelCase__ ) )

																			# Make sure we don't have nans
																			_UpperCamelCase					:		str 				=   after_outputs[0].cpu().numpy()
																			_UpperCamelCase					:		Optional[int] 				=   0
																			_UpperCamelCase					:		Dict 				=   np.amax(np.abs(out_a - out_a ) )
																			self.assertLessEqual(lowerCamelCase__ ,1E-5 )





	@unittest.skip(
	    reason='ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results.' )
	def 	UpperCamelCase_  ( self					:				List[Any] ):







							'''simple docstring'''
							pass





	@unittest.skip(
	    reason='ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results.' )
	def 	UpperCamelCase_  ( self					:				Optional[int] ):







							'''simple docstring'''
							pass





	@unittest.skip(
	    reason='ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results.' )
	def 	UpperCamelCase_  ( self					:				Union[str, Any] ):







							'''simple docstring'''
							pass





	@unittest.skip(reason='ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load' )
	def 	UpperCamelCase_  ( self					:				List[Any] ):







							'''simple docstring'''
							pass





	@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.' )
	def 	UpperCamelCase_  ( self					:				Tuple ):







							'''simple docstring'''
							pass





	@slow
	def 	UpperCamelCase_  ( self					:				str ):







							'''simple docstring'''
							for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													_UpperCamelCase					:		int 				=   ViTMAEModel.from_pretrained(lowerCamelCase__ )
													self.assertIsNotNone(lowerCamelCase__ )






def A__    (     ):
						_UpperCamelCase					:		List[Any] 				=   Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'							)
						return image






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





	@cached_property
	def 	UpperCamelCase_  ( self					:				Optional[int] ):







							'''simple docstring'''
							return ViTImageProcessor.from_pretrained('facebook/vit-mae-base' ) if is_vision_available() else None





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







							'''simple docstring'''
							# make random mask reproducible across the PT and TF model
							np.random.seed(2 )

							_UpperCamelCase					:		str 				=   ViTMAEForPreTraining.from_pretrained('facebook/vit-mae-base' ).to(lowerCamelCase__ )

							_UpperCamelCase					:		Any 				=   self.default_image_processor
							_UpperCamelCase					:		List[str] 				=   prepare_img()
							_UpperCamelCase					:		List[str] 				=   image_processor(images=lowerCamelCase__ ,return_tensors='pt' ).to(lowerCamelCase__ )

							# prepare a noise vector that will be also used for testing the TF model
							# (this way we can ensure that the PT and TF models operate on the same inputs)
							_UpperCamelCase					:		Any 				=   ViTMAEConfig()
							_UpperCamelCase					:		str 				=   int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2 )
							_UpperCamelCase					:		Any 				=   np.random.uniform(size=(1, num_patches) )

							# forward pass
							with torch.no_grad():
													_UpperCamelCase					:		Any 				=   model(**lowerCamelCase__ ,noise=torch.from_numpy(lowerCamelCase__ ).to(device=lowerCamelCase__ ) )

							# verify the logits
							_UpperCamelCase					:		str 				=   torch.Size((1, 196, 768) )
							self.assertEqual(outputs.logits.shape ,lowerCamelCase__ )

							_UpperCamelCase					:		List[str] 				=   torch.tensor(
							    [[-0.0_5_4_8, -1.7_0_2_3, -0.9_3_2_5], [0.3_7_2_1, -0.5_6_7_0, -0.2_2_3_3], [0.8_2_3_5, -1.3_8_7_8, -0.3_5_2_4]] )

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







"""simple docstring"""






def 			_lowercase				(  )						->   int:
			return 1


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else two_pence(x - 2	) + one_pence()


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else five_pence(x - 5	) + two_pence(__snake_case	)


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else ten_pence(x - 10	) + five_pence(__snake_case	)


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else twenty_pence(x - 20	) + ten_pence(__snake_case	)


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else fifty_pence(x - 50	) + twenty_pence(__snake_case	)


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else one_pound(x - 100	) + fifty_pence(__snake_case	)


def 			_lowercase				(  __snake_case	)						->   int:
			return 0 if x < 0 else two_pound(x - 200	) + one_pound(__snake_case	)


def 			_lowercase				(  __snake_case = 200	)						->   int:
			return two_pound(__snake_case	)


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