


"""simple docstring"""
import json
import os
from typing import List, Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


__SCREAMING_SNAKE_CASE				:     Optional[Any]		=     logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE				:     Optional[Any]		=     {
    '''vocab_file''': '''vocab.json''',
    '''merges_file''': '''merges.txt''',
}

__SCREAMING_SNAKE_CASE				:     str		=     {
    '''vocab_file''': {
        '''microsoft/biogpt''': '''https://huggingface.co/microsoft/biogpt/resolve/main/vocab.json''',
    },
    '''merges_file''': {'''microsoft/biogpt''': '''https://huggingface.co/microsoft/biogpt/resolve/main/merges.txt'''},
}

__SCREAMING_SNAKE_CASE				:     List[Any]		=     {
    '''microsoft/biogpt''': 1_024,
}







def     _a					(   _SCREAMING_SNAKE_CASE					)     ->					Dict:
							snake_case_     							=		set()
							snake_case_     							=		word[0]
							for char in word[1:]:
														pairs.add((prev_char, char)					)
														snake_case_     							=		char
							return pairs





class   __A  (snake_case__):





							'''simple docstring'''

							__lowercase:		str				   =     VOCAB_FILES_NAMES
							__lowercase:		List[str]				   =     PRETRAINED_VOCAB_FILES_MAP
							__lowercase:		List[str]				   =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							__lowercase:		Optional[Any]				   =     ["""input_ids""", """attention_mask"""]



							def __init__(					self				:   Union[str, Any]		,							UpperCAmelCase_				:   Dict		,							UpperCAmelCase_				:   List[str]		,							UpperCAmelCase_				:   List[Any]="<unk>"		,							UpperCAmelCase_				:   str="<s>"		,							UpperCAmelCase_				:   str="</s>"		,							UpperCAmelCase_				:   int="</s>"		,							UpperCAmelCase_				:   Tuple="<pad>"		,							**UpperCAmelCase_				:   Any		,							)       ->Tuple:



														"""simple docstring"""



														super().__init__(
														    bos_token=UpperCamelCase_		,							eos_token=UpperCamelCase_		,							sep_token=UpperCamelCase_		,							unk_token=UpperCamelCase_		,							pad_token=UpperCamelCase_		,							**UpperCamelCase_		,							)

														try:
																					import sacremoses
														except ImportError:
																					raise ImportError(
																					    """You need to install sacremoses to use BioGptTokenizer. """
																					    """See https://pypi.org/project/sacremoses/ for installation."""							)

														snake_case_     							=		'en'
														snake_case_     							=		sacremoses
														# cache of sm.MosesTokenizer instance
														snake_case_     							=		{}
														snake_case_     							=		{}
														with open(UpperCamelCase_		,							encoding="""utf-8"""							) as vocab_handle:
																					snake_case_     							=		json.load(UpperCamelCase_							)
														snake_case_     							=		{v: k for k, v in self.encoder.items()}
														with open(UpperCamelCase_		,							encoding="""utf-8"""							) as merges_handle:
																					snake_case_     							=		merges_handle.read().split("""\n"""							)[:-1]
														snake_case_     							=		[tuple(merge.split()[:2]							) for merge in merges]
														snake_case_     							=		dict(zip(UpperCamelCase_		,							range(len(UpperCamelCase_							)							)							)							)
														snake_case_     							=		{}



							@property
							def 		lowerCAmelCase							(					self				:   Tuple							)       ->List[str]:



														"""simple docstring"""



														return len(self.encoder							)



							def 		lowerCAmelCase							(					self				:   Tuple							)       ->List[str]:



														"""simple docstring"""



														return dict(self.encoder		,							**self.added_tokens_encoder							)



							def 		lowerCAmelCase							(					self				:   Optional[Any]		,							UpperCAmelCase_				:   int		,							UpperCAmelCase_				:   int							)       ->Optional[Any]:



														"""simple docstring"""



														if lang not in self.cache_moses_tokenizer:
																					snake_case_     							=		self.sm.MosesTokenizer(lang=UpperCamelCase_							)
																					snake_case_     							=		moses_tokenizer
														return self.cache_moses_tokenizer[lang].tokenize(
														    UpperCamelCase_		,							aggressive_dash_splits=UpperCamelCase_		,							return_str=UpperCamelCase_		,							escape=UpperCamelCase_							)



							def 		lowerCAmelCase							(					self				:   Any		,							UpperCAmelCase_				:   Dict		,							UpperCAmelCase_				:   str							)       ->List[str]:



														"""simple docstring"""



														if lang not in self.cache_moses_detokenizer:
																					snake_case_     							=		self.sm.MosesDetokenizer(lang=UpperCamelCase_							)
																					snake_case_     							=		moses_detokenizer
														return self.cache_moses_detokenizer[lang].detokenize(UpperCamelCase_							)



							def 		lowerCAmelCase							(					self				:   Optional[int]		,							UpperCAmelCase_				:   Optional[int]							)       ->Optional[Any]:



														"""simple docstring"""



														snake_case_     							=		tuple(token[:-1]							) + (token[-1] + '</w>',)
														if token in self.cache:
																					return self.cache[token]
														snake_case_     							=		get_pairs(UpperCamelCase_							)

														if not pairs:
																					return token + "</w>"

														while True:
																					snake_case_     							=		min(UpperCamelCase_		,							key=lambda UpperCAmelCase_							: self.bpe_ranks.get(UpperCamelCase_		,							float("""inf"""							)							)							)
																					if bigram not in self.bpe_ranks:
																												break
																					snake_case_     							=		bigram
																					snake_case_     							=		[]
																					snake_case_     							=		0
																					while i < len(UpperCamelCase_							):
																												try:
																																			snake_case_     							=		word.index(UpperCamelCase_		,							UpperCamelCase_							)
																												except ValueError:
																																			new_word.extend(word[i:]							)
																																			break
																												else:
																																			new_word.extend(word[i:j]							)
																																			snake_case_     							=		j

																												if word[i] == first and i < len(UpperCamelCase_							) - 1 and word[i + 1] == second:
																																			new_word.append(first + second							)
																																			i += 2
																												else:
																																			new_word.append(word[i]							)
																																			i += 1
																					snake_case_     							=		tuple(UpperCamelCase_							)
																					snake_case_     							=		new_word
																					if len(UpperCamelCase_							) == 1:
																												break
																					else:
																												snake_case_     							=		get_pairs(UpperCamelCase_							)
														snake_case_     							=		' '.join(UpperCamelCase_							)
														if word == "\n  </w>":
																					snake_case_     							=		'\n</w>'
														snake_case_     							=		word
														return word



							def 		lowerCAmelCase							(					self				:   List[Any]		,							UpperCAmelCase_				:   int		,							UpperCAmelCase_				:   List[str]=False							)       ->int:



														"""simple docstring"""



														if bypass_tokenizer:
																					snake_case_     							=		text.split()
														else:
																					snake_case_     							=		self.moses_tokenize(UpperCamelCase_		,							self.lang							)

														snake_case_     							=		[]
														for token in text:
																					if token:
																												split_tokens.extend(list(self.bpe(UpperCamelCase_							).split(""" """							)							)							)

														return split_tokens



							def 		lowerCAmelCase							(					self				:   Union[str, Any]		,							UpperCAmelCase_				:   Optional[int]							)       ->int:



														"""simple docstring"""



														return self.encoder.get(UpperCamelCase_		,							self.encoder.get(self.unk_token							)							)



							def 		lowerCAmelCase							(					self				:   List[Any]		,							UpperCAmelCase_				:   Union[str, Any]							)       ->Tuple:



														"""simple docstring"""



														return self.decoder.get(UpperCamelCase_		,							self.unk_token							)



							def 		lowerCAmelCase							(					self				:   Optional[int]		,							UpperCAmelCase_				:   Optional[Any]							)       ->List[Any]:



														"""simple docstring"""



														snake_case_     							=		[t.replace(""" """		,							""""""							).replace("""</w>"""		,							""" """							) for t in tokens]
														snake_case_     							=		''.join(UpperCamelCase_							).split()
														# detokenize
														snake_case_     							=		self.moses_detokenize(UpperCamelCase_		,							self.lang							)
														return text



							def 		lowerCAmelCase							(					self				:   Optional[int]		,							UpperCAmelCase_				:   List[int]		,							UpperCAmelCase_				:   Optional[List[int]] = None							)       ->List[int]:



														"""simple docstring"""



														if token_ids_a is None:
																					return [self.sep_token_id] + token_ids_a
														snake_case_     							=		[self.sep_token_id]
														return sep + token_ids_a + sep + token_ids_a



							def 		lowerCAmelCase							(					self				:   Union[str, Any]		,							UpperCAmelCase_				:   List[int]		,							UpperCAmelCase_				:   Optional[List[int]] = None		,							UpperCAmelCase_				:   bool = False							)       ->List[int]:



														"""simple docstring"""



														if already_has_special_tokens:
																					return super().get_special_tokens_mask(
																					    token_ids_a=UpperCamelCase_		,							token_ids_a=UpperCamelCase_		,							already_has_special_tokens=UpperCamelCase_							)
														# no bos used in fairseq
														if token_ids_a is not None:
																					return [1] + ([0] * len(UpperCamelCase_							)) + [1] + ([0] * len(UpperCamelCase_							))
														return [1] + ([0] * len(UpperCamelCase_							))



							def 		lowerCAmelCase							(					self				:   List[Any]		,							UpperCAmelCase_				:   List[int]		,							UpperCAmelCase_				:   Optional[List[int]] = None							)       ->List[int]:



														"""simple docstring"""



														snake_case_     							=		[self.sep_token_id]

														# no bos used in fairseq
														if token_ids_a is None:
																					return len(token_ids_a + sep							) * [0]
														return len(token_ids_a + sep							) * [0] + len(token_ids_a + sep							) * [1]



							def 		lowerCAmelCase							(					self				:   Tuple		,							UpperCAmelCase_				:   str		,							UpperCAmelCase_				:   Optional[str] = None							)       ->Tuple[str]:



														"""simple docstring"""



														if not os.path.isdir(UpperCamelCase_							):
																					logger.error(F"""Vocabulary path ({save_directory}) should be a directory"""							)
																					return
														snake_case_     							=		os.path.join(
														    UpperCamelCase_		,							(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]							)
														snake_case_     							=		os.path.join(
														    UpperCamelCase_		,							(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""merges_file"""]							)

														with open(UpperCamelCase_		,							"""w"""		,							encoding="""utf-8"""							) as f:
																					f.write(json.dumps(self.encoder		,							indent=2		,							sort_keys=UpperCamelCase_		,							ensure_ascii=UpperCamelCase_							) + """\n"""							)

														snake_case_     							=		0
														with open(UpperCamelCase_		,							"""w"""		,							encoding="""utf-8"""							) as writer:
																					for bpe_tokens, token_index in sorted(self.bpe_ranks.items()		,							key=lambda UpperCAmelCase_							: kv[1]							):
																												if index != token_index:
																																			logger.warning(
																																			    F"""Saving vocabulary to {merge_file}: BPE merge indices are not consecutive."""
																																			    """ Please check that the tokenizer is not corrupted!"""							)
																																			snake_case_     							=		token_index
																												writer.write(""" """.join(UpperCamelCase_							) + """\n"""							)
																												index += 1

														return vocab_file, merge_file



							def __getstate__(					self				:   Optional[int]							)       ->List[Any]:



														"""simple docstring"""



														snake_case_     							=		self.__dict__.copy()
														snake_case_     							=		None
														return state



							def __setstate__(					self				:   List[str]		,							UpperCAmelCase_				:   Dict							)       ->List[Any]:



														"""simple docstring"""



														snake_case_     							=		d

														try:
																					import sacremoses
														except ImportError:
																					raise ImportError(
																					    """You need to install sacremoses to use XLMTokenizer. """
																					    """See https://pypi.org/project/sacremoses/ for installation."""							)

														snake_case_     							=		sacremoses








'''simple docstring'''

def     __UpperCamelCase					(				_lowercase = 1000       )			->      int:
	_lowercase       :							Dict  	=		0
	_lowercase       :							int  	=		0
	while 1:
		num += 3
		if num >= n:
			break
		total += num
		num += 2
		if num >= n:
			break
		total += num
		num += 1
		if num >= n:
			break
		total += num
		num += 3
		if num >= n:
			break
		total += num
		num += 1
		if num >= n:
			break
		total += num
		num += 2
		if num >= n:
			break
		total += num
		num += 3
		if num >= n:
			break
		total += num
	return total


if __name__ == "__main__":
		print(F'''{solution() = }''')
