






"""simple docstring"""







import argparse
import collections
from pathlib import Path

import torch
from torch.serialization import default_restore_location

from transformers import BertConfig, DPRConfig, DPRContextEncoder, DPRQuestionEncoder, DPRReader


a :				Optional[int]      					=		collections.namedtuple(
    """CheckpointState""", ["""model_dict""", """optimizer_dict""", """scheduler_dict""", """offset""", """epoch""", """encoder_params"""]
)





def 						lowercase__(A						)				->CheckpointState:




						"""simple docstring"""



						print(f'''Reading saved model from {model_file}'''						)
						lowercase__				:      Optional[int]=       torch.load(A					,		map_location=lambda A					,		A						: default_restore_location(A					,		"cpu"						)						)
						return CheckpointState(**A						)


class     __UpperCAmelCase:




						"""simple docstring"""




						def __init__(   self       ,  snake_case__			):
												'''simple docstring'''
												lowercase__				:      Tuple=       src_file




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												raise NotImplementedError




						@staticmethod
						def 		UpperCAmelCase_       (   snake_case__       ,  *snake_case__       ,  **snake_case__			):
												'''simple docstring'''
												if comp_type.startswith("c"			):
																		return DPRContextEncoderState(*snake_case__       ,  **snake_case__			)
												if comp_type.startswith("q"			):
																		return DPRQuestionEncoderState(*snake_case__       ,  **snake_case__			)
												if comp_type.startswith("r"			):
																		return DPRReaderState(*snake_case__       ,  **snake_case__			)
												else:
																		raise ValueError("Component type must be either 'ctx_encoder', 'question_encoder' or 'reader'."			)


class     __UpperCAmelCase(   SCREAMING_SNAKE_CASE__							):




						"""simple docstring"""




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												lowercase__				:      Optional[Any]=       DPRContextEncoder(DPRConfig(**BertConfig.get_config_dict("bert-base-uncased"			)[0]			)			)
												print(F'''Loading DPR biencoder from {self.src_file}'''			)
												lowercase__				:      Dict=       load_states_from_checkpoint(self.src_file			)
												lowercase__,	lowercase__				:      List[Any]=       model.ctx_encoder, "ctx_model."
												# Fix changes from https://github.com/huggingface/transformers/commit/614fef1691edb806de976756d4948ecbcd0c0ca3
												lowercase__				:      Union[str, Any]=       {"bert_model.embeddings.position_ids": model.ctx_encoder.bert_model.embeddings.position_ids}
												for key, value in saved_state.model_dict.items():
																		if key.startswith(snake_case__			):
																								lowercase__				:      int=       key[len(snake_case__			) :]
																								if not key.startswith("encode_proj."			):
																														lowercase__				:      int=       "bert_model." + key
																								lowercase__				:      Optional[Any]=       value
												encoder.load_state_dict(snake_case__			)
												return model


class     __UpperCAmelCase(   SCREAMING_SNAKE_CASE__							):




						"""simple docstring"""




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												lowercase__				:      List[Any]=       DPRQuestionEncoder(DPRConfig(**BertConfig.get_config_dict("bert-base-uncased"			)[0]			)			)
												print(F'''Loading DPR biencoder from {self.src_file}'''			)
												lowercase__				:      Optional[Any]=       load_states_from_checkpoint(self.src_file			)
												lowercase__,	lowercase__				:      Union[str, Any]=       model.question_encoder, "question_model."
												# Fix changes from https://github.com/huggingface/transformers/commit/614fef1691edb806de976756d4948ecbcd0c0ca3
												lowercase__				:      Tuple=       {"bert_model.embeddings.position_ids": model.question_encoder.bert_model.embeddings.position_ids}
												for key, value in saved_state.model_dict.items():
																		if key.startswith(snake_case__			):
																								lowercase__				:      Tuple=       key[len(snake_case__			) :]
																								if not key.startswith("encode_proj."			):
																														lowercase__				:      int=       "bert_model." + key
																								lowercase__				:      Optional[int]=       value
												encoder.load_state_dict(snake_case__			)
												return model


class     __UpperCAmelCase(   SCREAMING_SNAKE_CASE__							):




						"""simple docstring"""




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												lowercase__				:      Optional[int]=       DPRReader(DPRConfig(**BertConfig.get_config_dict("bert-base-uncased"			)[0]			)			)
												print(F'''Loading DPR reader from {self.src_file}'''			)
												lowercase__				:      Optional[int]=       load_states_from_checkpoint(self.src_file			)
												# Fix changes from https://github.com/huggingface/transformers/commit/614fef1691edb806de976756d4948ecbcd0c0ca3
												lowercase__				:      Optional[int]=       {
												    "encoder.bert_model.embeddings.position_ids": model.span_predictor.encoder.bert_model.embeddings.position_ids
												}
												for key, value in saved_state.model_dict.items():
																		if key.startswith("encoder."			) and not key.startswith("encoder.encode_proj"			):
																								lowercase__				:      Dict=       "encoder.bert_model." + key[len("encoder."			) :]
																		lowercase__				:      Any=       value
												model.span_predictor.load_state_dict(snake_case__			)
												return model





def 						lowercase__(A					,		A					,		A						)				->int:




						"""simple docstring"""



						lowercase__				:      Tuple=       Path(A						)
						dest_dir.mkdir(exist_ok=A						)

						lowercase__				:      Any=       DPRState.from_type(A					,		src_file=A						)
						lowercase__				:      Tuple=       dpr_state.load_dpr_model()
						model.save_pretrained(A						)
						model.from_pretrained(A						)  # sanity check


if __name__ == "__main__":
			a :				List[str]      					=		argparse.ArgumentParser()
			# Required parameters
			parser.add_argument(
			    """--type""", type=str, help="""Type of the component to convert: 'ctx_encoder', 'question_encoder' or 'reader'."""
			)
			parser.add_argument(
			    """--src""",
			    type=str,
			    help=(
			        """Path to the dpr checkpoint file. They can be downloaded from the official DPR repo"""
			        """ https://github.com/facebookresearch/DPR. Note that in the official repo, both encoders are stored in the"""
			        """ 'retriever' checkpoints."""
			    ),
			)
			parser.add_argument("""--dest""", type=str, default=None, help="""Path to the output PyTorch model directory.""")
			a :				Dict      					=		parser.parse_args()

			a :				Optional[Any]      					=		Path(args.src)
			a :				List[str]      					=		F"""converted-{src_file.name}""" if args.dest is None else args.dest
			a :				List[Any]      					=		Path(dest_dir)
			assert src_file.exists()
			assert (
			    args.type is not None
			), "Please specify the component type of the DPR model to convert: 'ctx_encoder', 'question_encoder' or 'reader'."
			convert(args.type, src_file, dest_dir)














"""simple docstring"""







def 						lowercase__(A = 1_000						)				->int:




						"""simple docstring"""



						lowercase__				:      Any=       [0, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8]
						# number of letters in twenty, thirty, ..., ninety (0 for numbers less than
						# 20 due to inconsistency in teens)
						lowercase__				:      List[str]=       [0, 0, 6, 6, 5, 5, 5, 7, 6, 6]

						lowercase__				:      Dict=       0

						for i in range(1					,		n + 1						):
												if i < 1_000:
																		if i >= 100:
																								# add number of letters for "n hundred"
																								count += ones_counts[i // 100] + 7

																								if i % 100 != 0:
																														# add number of letters for "and" if number is not multiple
																														# of 100
																														count += 3

																		if 0 < i % 100 < 20:
																								# add number of letters for one, two, three, ..., nineteen
																								# (could be combined with below if not for inconsistency in
																								# teens)
																								count += ones_counts[i % 100]
																		else:
																								# add number of letters for twenty, twenty one, ..., ninety
																								# nine
																								count += ones_counts[i % 10]
																								count += tens_counts[(i % 100 - i % 10) // 10]
												else:
																		count += ones_counts[i // 1_000] + 8
						return count


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






