



'''simple docstring'''

import argparse
import os

import torch

from transformers import FlavaConfig, FlavaForPreTraining
from transformers.models.flava.convert_dalle_to_flava_codebook import convert_dalle_checkpoint



def 					__lowerCamelCase					(				lowerCAmelCase_  )      ->				Optional[int]:
		# encoder.embeddings are double copied in original FLAVA
		return sum(param.float().sum() if 'encoder.embeddings' not in key else 0 for key, param in state_dict.items()  )



def 					__lowerCamelCase					(				lowerCAmelCase_						,      lowerCAmelCase_  )      ->				List[str]:
		_a					:				Tuple				=							{}

		for key, value in state_dict.items():
				if "text_encoder.embeddings" in key or "image_encoder.embeddings" in key:
						continue

				_a					:				str				=							key.replace('heads.cmd.mim_head.cls.predictions'						,      'mmm_image_head'  )
				_a					:				Any				=							key.replace('heads.cmd.mlm_head.cls.predictions'						,      'mmm_text_head'  )
				_a					:				Optional[int]				=							key.replace('heads.cmd.itm_head.cls'						,      'itm_head'  )
				_a					:				Optional[int]				=							key.replace('heads.cmd.itm_head.pooler'						,      'itm_head.pooler'  )
				_a					:				List[Any]				=							key.replace('heads.cmd.clip_head.logit_scale'						,      'flava.logit_scale'  )
				_a					:				Optional[int]				=							key.replace('heads.fairseq_mlm.cls.predictions'						,      'mlm_head'  )
				_a					:				Any				=							key.replace('heads.imagenet.mim_head.cls.predictions'						,      'mim_head'  )
				_a					:				List[str]				=							key.replace('mm_text_projection'						,      'flava.text_to_mm_projection'  )
				_a					:				Any				=							key.replace('mm_image_projection'						,      'flava.image_to_mm_projection'  )
				_a					:				Any				=							key.replace('image_encoder.module'						,      'flava.image_model'  )
				_a					:				Tuple				=							key.replace('text_encoder.module'						,      'flava.text_model'  )
				_a					:				Optional[int]				=							key.replace('mm_encoder.module.encoder.cls_token'						,      'flava.multimodal_model.cls_token'  )
				_a					:				Tuple				=							key.replace('mm_encoder.module'						,      'flava.multimodal_model'  )
				_a					:				Optional[int]				=							key.replace('text_projection'						,      'flava.text_projection'  )
				_a					:				str				=							key.replace('image_projection'						,      'flava.image_projection'  )

				_a					:				Tuple				=							value.float()

		for key, value in codebook_state_dict.items():
				_a					:				List[Any]				=							value

		return upgrade



@torch.no_grad()
def 					__lowerCamelCase					(				lowerCAmelCase_						,      lowerCAmelCase_						,      lowerCAmelCase_						,      lowerCAmelCase_=None  )      ->				Any:
		if config_path is not None:
				_a					:				List[str]				=							FlavaConfig.from_pretrained(lowerCAmelCase_  )
		else:
				_a					:				List[Any]				=							FlavaConfig()

		_a					:				List[Any]				=							FlavaForPreTraining(lowerCAmelCase_  ).eval()

		_a					:				List[str]				=							convert_dalle_checkpoint(lowerCAmelCase_						,      lowerCAmelCase_						,      save_checkpoint=lowerCAmelCase_  )

		if os.path.exists(lowerCAmelCase_  ):
				_a					:				int				=							torch.load(lowerCAmelCase_						,      map_location='cpu'  )
		else:
				_a					:				str				=							torch.hub.load_state_dict_from_url(lowerCAmelCase_						,      map_location='cpu'  )

		_a					:				int				=							upgrade_state_dict(lowerCAmelCase_						,      lowerCAmelCase_  )
		hf_model.load_state_dict(lowerCAmelCase_  )
		_a					:				Any				=							hf_model.state_dict()
		_a					:				Dict				=							count_parameters(lowerCAmelCase_  )
		_a					:				Dict				=							count_parameters(lowerCAmelCase_  ) + count_parameters(lowerCAmelCase_  )

		assert torch.allclose(lowerCAmelCase_						,      lowerCAmelCase_						,      atol=1E-3  )

		hf_model.save_pretrained(lowerCAmelCase_  )


if __name__ == "__main__":
							__lowerCAmelCase						      =       argparse.ArgumentParser()
							parser.add_argument('''--pytorch_dump_folder_path''', default=None, type=str, help='''Path to the output PyTorch model.''')
							parser.add_argument('''--checkpoint_path''', default=None, type=str, help='''Path to flava checkpoint''')
							parser.add_argument('''--codebook_path''', default=None, type=str, help='''Path to flava codebook checkpoint''')
							parser.add_argument('''--config_path''', default=None, type=str, help='''Path to hf config.json of model to convert''')
							__lowerCAmelCase						      =       parser.parse_args()

							convert_flava_checkpoint(args.checkpoint_path, args.codebook_path, args.pytorch_dump_folder_path, args.config_path)









'''simple docstring'''

from math import sqrt



def 					__lowerCamelCase					(				lowerCAmelCase_  )      ->				int:
		_a					:				Dict				=							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_ = 10000  )      ->				int:
		_a					:				Union[str, Any]				=							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())))




