




"""simple docstring"""




import argparse
import json
from pathlib import Path

import requests
import torch
from huggingface_hub import hf_hub_download
from PIL import Image

from transformers import ViTConfig, ViTForImageClassification, ViTImageProcessor, ViTModel
from transformers.utils import logging


logging.set_verbosity_info()
a_        =       logging.get_logger(__name__)







def      __UpperCAmelCase     ( __UpperCamelCase	,				__UpperCamelCase=False	):
			__lowercase			:  Optional[Any]								=       []
			for i in range(config.num_hidden_layers	):
						# encoder layers: output projection, 2 feedforward neural networks and 2 layernorms
						rename_keys.append((f"""blocks.{i}.norm1.weight""", f"""vit.encoder.layer.{i}.layernorm_before.weight""")	)
						rename_keys.append((f"""blocks.{i}.norm1.bias""", f"""vit.encoder.layer.{i}.layernorm_before.bias""")	)
						rename_keys.append((f"""blocks.{i}.attn.proj.weight""", f"""vit.encoder.layer.{i}.attention.output.dense.weight""")	)
						rename_keys.append((f"""blocks.{i}.attn.proj.bias""", f"""vit.encoder.layer.{i}.attention.output.dense.bias""")	)
						rename_keys.append((f"""blocks.{i}.norm2.weight""", f"""vit.encoder.layer.{i}.layernorm_after.weight""")	)
						rename_keys.append((f"""blocks.{i}.norm2.bias""", f"""vit.encoder.layer.{i}.layernorm_after.bias""")	)
						rename_keys.append((f"""blocks.{i}.mlp.fc1.weight""", f"""vit.encoder.layer.{i}.intermediate.dense.weight""")	)
						rename_keys.append((f"""blocks.{i}.mlp.fc1.bias""", f"""vit.encoder.layer.{i}.intermediate.dense.bias""")	)
						rename_keys.append((f"""blocks.{i}.mlp.fc2.weight""", f"""vit.encoder.layer.{i}.output.dense.weight""")	)
						rename_keys.append((f"""blocks.{i}.mlp.fc2.bias""", f"""vit.encoder.layer.{i}.output.dense.bias""")	)

			# projection layer + position embeddings
			rename_keys.extend(
			    [
			        ('''cls_token''', '''vit.embeddings.cls_token'''),
			        ('''patch_embed.proj.weight''', '''vit.embeddings.patch_embeddings.projection.weight'''),
			        ('''patch_embed.proj.bias''', '''vit.embeddings.patch_embeddings.projection.bias'''),
			        ('''pos_embed''', '''vit.embeddings.position_embeddings'''),
			    ]	)

			if base_model:
						# layernorm + pooler
						rename_keys.extend(
						    [
						        ('''norm.weight''', '''layernorm.weight'''),
						        ('''norm.bias''', '''layernorm.bias'''),
						    ]	)

						# if just the base model, we should remove "vit" from all keys that start with "vit"
						__lowercase			:  str								=       [(pair[0], pair[1][4:]) if pair[1].startswith('''vit'''	) else pair for pair in rename_keys]
			else:
						# layernorm + classification head
						rename_keys.extend(
						    [
						        ('''norm.weight''', '''vit.layernorm.weight'''),
						        ('''norm.bias''', '''vit.layernorm.bias'''),
						        ('''head.weight''', '''classifier.weight'''),
						        ('''head.bias''', '''classifier.bias'''),
						    ]	)

			return rename_keys







def      __UpperCAmelCase     ( __UpperCamelCase	,				__UpperCamelCase	,				__UpperCamelCase=False	):
			for i in range(config.num_hidden_layers	):
						if base_model:
									__lowercase			:  List[Any]								=       ''''''
						else:
									__lowercase			:  Dict								=       '''vit.'''
						# read in weights + bias of input projection layer (in timm, this is a single matrix + bias)
						__lowercase			:  Any								=       state_dict.pop(f"""blocks.{i}.attn.qkv.weight"""	)
						__lowercase			:  int								=       state_dict.pop(f"""blocks.{i}.attn.qkv.bias"""	)
						# next, add query, keys and values (in that order) to the state dict
						__lowercase			:  List[str]								=       in_proj_weight[
						    : config.hidden_size, :
						]
						__lowercase			:  str								=       in_proj_bias[: config.hidden_size]
						__lowercase			:  str								=       in_proj_weight[
						    config.hidden_size : config.hidden_size * 2, :
						]
						__lowercase			:  Any								=       in_proj_bias[
						    config.hidden_size : config.hidden_size * 2
						]
						__lowercase			:  Tuple								=       in_proj_weight[
						    -config.hidden_size :, :
						]
						__lowercase			:  Tuple								=       in_proj_bias[-config.hidden_size :]







def      __UpperCAmelCase     ( __UpperCamelCase	):
			__lowercase			:  Union[str, Any]								=       ['''head.weight''', '''head.bias''']
			for k in ignore_keys:
						state_dict.pop(lowerCAmelCase_	,				lowerCAmelCase_	)







def      __UpperCAmelCase     ( __UpperCamelCase	,				__UpperCamelCase	,				__UpperCamelCase	):
			__lowercase			:  List[str]								=       dct.pop(lowerCAmelCase_	)
			__lowercase			:  List[Any]								=       val







def      __UpperCAmelCase     ( ):
			__lowercase			:  Dict								=       '''http://images.cocodataset.org/val2017/000000039769.jpg'''
			__lowercase			:  str								=       Image.open(requests.get(lowerCAmelCase_	,				stream=lowerCAmelCase_	).raw	)
			return im







@torch.no_grad()
def      __UpperCAmelCase     ( __UpperCamelCase	,				__UpperCamelCase	,				__UpperCamelCase=True	):
			__lowercase			:  str								=       ViTConfig()
			# patch_size
			if model_name[-1] == "8":
						__lowercase			:  Optional[Any]								=       8
			# set labels if required
			if not base_model:
						__lowercase			:  int								=       10_00
						__lowercase			:  Optional[int]								=       '''huggingface/label-files'''
						__lowercase			:  List[Any]								=       '''imagenet-1k-id2label.json'''
						__lowercase			:  List[Any]								=       json.load(open(hf_hub_download(lowerCAmelCase_	,				lowerCAmelCase_	,				repo_type='''dataset'''	)	,				'''r'''	)	)
						__lowercase			:  Optional[Any]								=       {int(lowerCAmelCase_	): v for k, v in idalabel.items()}
						__lowercase			:  Dict								=       idalabel
						__lowercase			:  Optional[Any]								=       {v: k for k, v in idalabel.items()}
			# size of the architecture
			if model_name in ["dino_vits8", "dino_vits16"]:
						__lowercase			:  Any								=       3_84
						__lowercase			:  Optional[int]								=       15_36
						__lowercase			:  str								=       12
						__lowercase			:  List[Any]								=       6

			# load original model from torch hub
			__lowercase			:  int								=       torch.hub.load('''facebookresearch/dino:main'''	,				lowerCAmelCase_	)
			original_model.eval()

			# load state_dict of original model, remove and rename some keys
			__lowercase			:  Tuple								=       original_model.state_dict()
			if base_model:
						remove_classification_head_(lowerCAmelCase_	)
			__lowercase			:  List[Any]								=       create_rename_keys(lowerCAmelCase_	,				base_model=lowerCAmelCase_	)
			for src, dest in rename_keys:
						rename_key(lowerCAmelCase_	,				lowerCAmelCase_	,				lowerCAmelCase_	)
			read_in_q_k_v(lowerCAmelCase_	,				lowerCAmelCase_	,				lowerCAmelCase_	)

			# load HuggingFace model
			if base_model:
						__lowercase			:  Tuple								=       ViTModel(lowerCAmelCase_	,				add_pooling_layer=lowerCAmelCase_	).eval()
			else:
						__lowercase			:  str								=       ViTForImageClassification(lowerCAmelCase_	).eval()
			model.load_state_dict(lowerCAmelCase_	)

			# Check outputs on an image, prepared by ViTImageProcessor
			__lowercase			:  int								=       ViTImageProcessor()
			__lowercase			:  Optional[Any]								=       image_processor(images=prepare_img()	,				return_tensors='''pt'''	)
			__lowercase			:  Dict								=       encoding['''pixel_values''']
			__lowercase			:  Union[str, Any]								=       model(lowerCAmelCase_	)

			if base_model:
						__lowercase			:  str								=       original_model(lowerCAmelCase_	)
						assert torch.allclose(lowerCAmelCase_	,				outputs.last_hidden_state[:, 0, :]	,				atol=1e-1	)
			else:
						__lowercase			:  str								=       original_model(lowerCAmelCase_	)
						assert logits.shape == outputs.logits.shape
						assert torch.allclose(lowerCAmelCase_	,				outputs.logits	,				atol=1e-3	)

			Path(lowerCAmelCase_	).mkdir(exist_ok=lowerCAmelCase_	)
			print(f"""Saving model {model_name} to {pytorch_dump_folder_path}"""	)
			model.save_pretrained(lowerCAmelCase_	)
			print(f"""Saving image processor to {pytorch_dump_folder_path}"""	)
			image_processor.save_pretrained(lowerCAmelCase_	)


if __name__ == "__main__":
			a_        =       argparse.ArgumentParser()
			# Required parameters
			parser.add_argument(
			    '--model_name',
			    default='dino_vitb16',
			    type=str,
			    help='Name of the model trained with DINO you\'d like to convert.',
			)
			parser.add_argument(
			    '--pytorch_dump_folder_path', default=None, type=str, help='Path to the output PyTorch model directory.'
			)
			parser.add_argument(
			    '--base_model',
			    action='store_true',
			    help='Whether to only convert the base model (no projection head weights).',
			)

			parser.set_defaults(base_model=True)
			a_        =       parser.parse_args()
			convert_vit_checkpoint(args.model_name, args.pytorch_dump_folder_path, args.base_model)










def 							__snake_case							(    )				->						int:
    return 1


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


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


def 							__snake_case							(    lowerCAmelCase_	)				->						int:
    return 0 if x < 0 else ten_pence(x - 1_0	) + five_pence(lowerCAmelCase_	)


def 							__snake_case							(    lowerCAmelCase_	)				->						int:
    return 0 if x < 0 else twenty_pence(x - 2_0	) + ten_pence(lowerCAmelCase_	)


def 							__snake_case							(    lowerCAmelCase_	)				->						int:
    return 0 if x < 0 else fifty_pence(x - 5_0	) + twenty_pence(lowerCAmelCase_	)


def 							__snake_case							(    lowerCAmelCase_	)				->						int:
    return 0 if x < 0 else one_pound(x - 1_0_0	) + fifty_pence(lowerCAmelCase_	)


def 							__snake_case							(    lowerCAmelCase_	)				->						int:
    return 0 if x < 0 else two_pound(x - 2_0_0	) + one_pound(lowerCAmelCase_	)


def 							__snake_case							(    lowerCAmelCase_ = 2_0_0	)				->						int:
    return two_pound(lowerCAmelCase_	)


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