





import json
import os
from functools import lru_cache
from typing import List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


_lowerCamelCase       =	logging.get_logger(__name__)

_lowerCamelCase       =	{
    'vocab_file': 'vocab.json',
    'merges_file': 'merges.txt',
}

_lowerCamelCase       =	{
    'vocab_file': {
        'roberta-base': 'https://huggingface.co/roberta-base/resolve/main/vocab.json',
        'roberta-large': 'https://huggingface.co/roberta-large/resolve/main/vocab.json',
        'roberta-large-mnli': 'https://huggingface.co/roberta-large-mnli/resolve/main/vocab.json',
        'distilroberta-base': 'https://huggingface.co/distilroberta-base/resolve/main/vocab.json',
        'roberta-base-openai-detector': 'https://huggingface.co/roberta-base-openai-detector/resolve/main/vocab.json',
        'roberta-large-openai-detector': (
            'https://huggingface.co/roberta-large-openai-detector/resolve/main/vocab.json'
        ),
    },
    'merges_file': {
        'roberta-base': 'https://huggingface.co/roberta-base/resolve/main/merges.txt',
        'roberta-large': 'https://huggingface.co/roberta-large/resolve/main/merges.txt',
        'roberta-large-mnli': 'https://huggingface.co/roberta-large-mnli/resolve/main/merges.txt',
        'distilroberta-base': 'https://huggingface.co/distilroberta-base/resolve/main/merges.txt',
        'roberta-base-openai-detector': 'https://huggingface.co/roberta-base-openai-detector/resolve/main/merges.txt',
        'roberta-large-openai-detector': (
            'https://huggingface.co/roberta-large-openai-detector/resolve/main/merges.txt'
        ),
    },
}

_lowerCamelCase       =	{
    'roberta-base': 512,
    'roberta-large': 512,
    'roberta-large-mnli': 512,
    'distilroberta-base': 512,
    'roberta-base-openai-detector': 512,
    'roberta-large-openai-detector': 512,
}






@lru_cache()
def  SCREAMING_SNAKE_CASE__							(				):
		SCREAMING_SNAKE_CASE__								=					(
		    list(range(ord("""!"""			)    ,      ord("""~"""			) + 1			)			) + list(range(ord("""¡"""			)    ,      ord("""¬"""			) + 1			)			) + list(range(ord("""®"""			)    ,      ord("""ÿ"""			) + 1			)			)
		)
		SCREAMING_SNAKE_CASE__								=					bs[:]
		SCREAMING_SNAKE_CASE__								=					0
		for b in range(2**8			):
				if b not in bs:
						bs.append(UpperCamelCase__			)
						cs.append(2**8 + n			)
						n += 1
		SCREAMING_SNAKE_CASE__								=					[chr(UpperCamelCase__			) for n in cs]
		return dict(zip(UpperCamelCase__    ,      UpperCamelCase__			)			)






def  SCREAMING_SNAKE_CASE__							(				UpperCamelCase__:							Any			):
		SCREAMING_SNAKE_CASE__								=					set()
		SCREAMING_SNAKE_CASE__								=					word[0]
		for char in word[1:]:
				pairs.add((prev_char, char)			)
				SCREAMING_SNAKE_CASE__								=					char
		return pairs




class      UpperCamelCase_				(   UpperCamelCase__			):
							lowerCamelCase_							=    VOCAB_FILES_NAMES
							lowerCamelCase_							=    PRETRAINED_VOCAB_FILES_MAP
							lowerCamelCase_							=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							lowerCamelCase_							=    ["input_ids", "attention_mask"]


							def __init__(							self			:Dict							, __A			:str							, __A			:str							, __A			:str="replace"							, __A			:List[Any]="<s>"							, __A			:List[Any]="</s>"							, __A			:int="</s>"							, __A			:Optional[int]="<s>"							, __A			:List[Any]="<unk>"							, __A			:Union[str, Any]="<pad>"							, __A			:Optional[Any]="<mask>"							, __A			:int=False							, **__A			:Dict							, )      ->      Optional[int]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=					AddedToken(__A							, lstrip=__A							, rstrip=__A						) if isinstance(__A							, __A						) else bos_token
									SCREAMING_SNAKE_CASE__								=					AddedToken(__A							, lstrip=__A							, rstrip=__A						) if isinstance(__A							, __A						) else eos_token
									SCREAMING_SNAKE_CASE__								=					AddedToken(__A							, lstrip=__A							, rstrip=__A						) if isinstance(__A							, __A						) else sep_token
									SCREAMING_SNAKE_CASE__								=					AddedToken(__A							, lstrip=__A							, rstrip=__A						) if isinstance(__A							, __A						) else cls_token
									SCREAMING_SNAKE_CASE__								=					AddedToken(__A							, lstrip=__A							, rstrip=__A						) if isinstance(__A							, __A						) else unk_token
									SCREAMING_SNAKE_CASE__								=					AddedToken(__A							, lstrip=__A							, rstrip=__A						) if isinstance(__A							, __A						) else pad_token

									# Mask token behave like a normal word, i.e. include the space before it
									SCREAMING_SNAKE_CASE__								=					AddedToken(__A							, lstrip=__A							, rstrip=__A						) if isinstance(__A							, __A						) else mask_token

									super().__init__(
									    errors=__A							, bos_token=__A							, eos_token=__A							, unk_token=__A							, sep_token=__A							, cls_token=__A							, pad_token=__A							, mask_token=__A							, add_prefix_space=__A							, **__A							, )

									with open(__A							, encoding="""utf-8"""						) as vocab_handle:
											SCREAMING_SNAKE_CASE__								=					json.load(__A						)
									SCREAMING_SNAKE_CASE__								=					{v: k for k, v in self.encoder.items()}
									SCREAMING_SNAKE_CASE__								=					errors  # how to handle errors in decoding
									SCREAMING_SNAKE_CASE__								=					bytes_to_unicode()
									SCREAMING_SNAKE_CASE__								=					{v: k for k, v in self.byte_encoder.items()}
									with open(__A							, encoding="""utf-8"""						) as merges_handle:
											SCREAMING_SNAKE_CASE__								=					merges_handle.read().split("""\n"""						)[1:-1]
									SCREAMING_SNAKE_CASE__								=					[tuple(merge.split()						) for merge in bpe_merges]
									SCREAMING_SNAKE_CASE__								=					dict(zip(__A							, range(len(__A						)						)						)						)
									SCREAMING_SNAKE_CASE__								=					{}
									SCREAMING_SNAKE_CASE__								=					add_prefix_space

									# Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
									SCREAMING_SNAKE_CASE__								=					re.compile(r"""'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+"""						)


							@property
							def    _snake_case     (							self			:Tuple						)      ->      Optional[Any]:



									"""simple docstring"""



									return len(self.encoder						)


							def    _snake_case     (							self			:int						)      ->      int:



									"""simple docstring"""



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


							def    _snake_case     (							self			:str							, __A			:Optional[int]						)      ->      Dict:



									"""simple docstring"""



									if token in self.cache:
											return self.cache[token]
									SCREAMING_SNAKE_CASE__								=					tuple(__A						)
									SCREAMING_SNAKE_CASE__								=					get_pairs(__A						)

									if not pairs:
											return token

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

													if word[i] == first and i < len(__A						) - 1 and word[i + 1] == second:
															new_word.append(first + second						)
															i += 2
													else:
															new_word.append(word[i]						)
															i += 1
											SCREAMING_SNAKE_CASE__								=					tuple(__A						)
											SCREAMING_SNAKE_CASE__								=					new_word
											if len(__A						) == 1:
													break
											else:
													SCREAMING_SNAKE_CASE__								=					get_pairs(__A						)
									SCREAMING_SNAKE_CASE__								=					""" """.join(__A						)
									SCREAMING_SNAKE_CASE__								=					word
									return word


							def    _snake_case     (							self			:Optional[Any]							, __A			:Optional[Any]						)      ->      Optional[int]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=					[]
									for token in re.findall(self.pat							, __A						):
											SCREAMING_SNAKE_CASE__								=					"""""".join(
											    self.byte_encoder[b] for b in token.encode("""utf-8"""						)						)  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
											bpe_tokens.extend(bpe_token for bpe_token in self.bpe(__A						).split(""" """						)						)
									return bpe_tokens


							def    _snake_case     (							self			:Optional[Any]							, __A			:Optional[Any]						)      ->      Optional[Any]:



									"""simple docstring"""



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


							def    _snake_case     (							self			:List[str]							, __A			:Union[str, Any]						)      ->      str:



									"""simple docstring"""



									return self.decoder.get(__A						)


							def    _snake_case     (							self			:int							, __A			:List[str]						)      ->      Dict:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=					"""""".join(__A						)
									SCREAMING_SNAKE_CASE__								=					bytearray([self.byte_decoder[c] for c in text]						).decode("""utf-8"""							, errors=self.errors						)
									return text


							def    _snake_case     (							self			:str							, __A			:str							, __A			:Optional[str] = None						)      ->      Tuple[str]:



									"""simple docstring"""



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

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

									SCREAMING_SNAKE_CASE__								=					0
									with open(__A							, """w"""							, encoding="""utf-8"""						) as writer:
											writer.write("""#version: 0.2\n"""						)
											for bpe_tokens, token_index in sorted(self.bpe_ranks.items()							, key=lambda __A						: 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!"""						)
															SCREAMING_SNAKE_CASE__								=					token_index
													writer.write(""" """.join(__A						) + """\n"""						)
													index += 1

									return vocab_file, merge_file


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



									"""simple docstring"""



									if token_ids_a is None:
											return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
									SCREAMING_SNAKE_CASE__								=					[self.cls_token_id]
									SCREAMING_SNAKE_CASE__								=					[self.sep_token_id]
									return cls + token_ids_a + sep + sep + token_ids_a + sep


							def    _snake_case     (							self			:List[str]							, __A			:List[int]							, __A			:Optional[List[int]] = None							, __A			:bool = False						)      ->      List[int]:



									"""simple docstring"""



									if already_has_special_tokens:
											return super().get_special_tokens_mask(
											    token_ids_a=__A							, token_ids_a=__A							, already_has_special_tokens=__A						)

									if token_ids_a is None:
											return [1] + ([0] * len(__A						)) + [1]
									return [1] + ([0] * len(__A						)) + [1, 1] + ([0] * len(__A						)) + [1]


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



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=					[self.sep_token_id]
									SCREAMING_SNAKE_CASE__								=					[self.cls_token_id]

									if token_ids_a is None:
											return len(cls + token_ids_a + sep						) * [0]
									return len(cls + token_ids_a + sep + sep + token_ids_a + sep						) * [0]


							def    _snake_case     (							self			:Optional[int]							, __A			:List[str]							, __A			:Tuple=False							, **__A			:Union[str, Any]						)      ->      Tuple:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=					kwargs.pop("""add_prefix_space"""							, self.add_prefix_space						)
									if (is_split_into_words or add_prefix_space) and (len(__A						) > 0 and not text[0].isspace()):
											SCREAMING_SNAKE_CASE__								=					""" """ + text
									return (text, kwargs)



"""simple docstring"""


import math
from decimal import Decimal, getcontext






def    a__       ( __lowercase = 400_0000      )		->		int:

				try:
								_A         =	int(__lowercase      )
				except (TypeError, ValueError):
								raise TypeError("Parameter n must be int or castable to int."      )
				if n <= 0:
								raise ValueError("Parameter n must be greater than or equal to one."      )
				_A         =	100
				_A         =	(Decimal(5      ) ** Decimal(0.5      ) + 1) / Decimal(2      )

				_A         =	(math.floor(math.log(n * (phi + 2)   ,	__lowercase      ) - 1      ) // 3) * 3 + 2
				_A         =	Decimal(round(phi ** Decimal(index + 1      )      )      ) / (phi + 2)
				_A         =	num // 2
				return int(__lowercase      )


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