





"""simple docstring"""
import json
import os
import re
import unicodedata
from typing import Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer, _is_control, _is_punctuation, _is_whitespace
from ...utils import logging


lowerCamelCase_          =	logging.get_logger(__name__)

lowerCamelCase_          =	{
    "vocab_file": "vocab.json",
    "merges_file": "merges.txt",
}

lowerCamelCase_          =	{
    "vocab_file": {"openai-gpt": "https://huggingface.co/openai-gpt/resolve/main/vocab.json"},
    "merges_file": {"openai-gpt": "https://huggingface.co/openai-gpt/resolve/main/merges.txt"},
}

lowerCamelCase_          =	{
    "openai-gpt": 5_1_2,
}



def   __lowerCamelCase     (							a_  :	Optional[Any]							)    ->   Any:
						__SCREAMING_SNAKE_CASE     :Tuple	       =						text.strip()
						if not text:
												return []
						__SCREAMING_SNAKE_CASE     :int	       =						text.split()
						return tokens






class       _SCREAMING_SNAKE_CASE(     A						):




							def __init__(		self	,SCREAMING_SNAKE_CASE__=True	,SCREAMING_SNAKE_CASE__=None	,SCREAMING_SNAKE_CASE__=True	,SCREAMING_SNAKE_CASE__=None	,SCREAMING_SNAKE_CASE__=True	,)    ->   int:





													"""simple docstring"""






													if never_split is None:
																			__SCREAMING_SNAKE_CASE     :Optional[int]	       =						[]
													__SCREAMING_SNAKE_CASE     :str	       =						do_lower_case
													__SCREAMING_SNAKE_CASE     :List[Any]	       =						set(SCREAMING_SNAKE_CASE__							)
													__SCREAMING_SNAKE_CASE     :Dict	       =						tokenize_chinese_chars
													__SCREAMING_SNAKE_CASE     :Tuple	       =						strip_accents
													__SCREAMING_SNAKE_CASE     :Optional[Any]	       =						do_split_on_punc




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__=None							)    ->   List[str]:





													"""simple docstring"""






													__SCREAMING_SNAKE_CASE     :Optional[Any]	       =						self.never_split.union(set(SCREAMING_SNAKE_CASE__							)							) if never_split else self.never_split
													__SCREAMING_SNAKE_CASE     :int	       =						self._clean_text(SCREAMING_SNAKE_CASE__							)

													# This was added on November 1st, 2018 for the multilingual and Chinese
													# models. This is also applied to the English models now, but it doesn't
													# matter since the English models were not trained on any Chinese data
													# and generally don't have any Chinese data in them (there are Chinese
													# characters in the vocabulary because Wikipedia does have some Chinese
													# words in the English Wikipedia.).
													if self.tokenize_chinese_chars:
																			__SCREAMING_SNAKE_CASE     :Tuple	       =						self._tokenize_chinese_chars(SCREAMING_SNAKE_CASE__							)
													# prevents treating the same character with different unicode codepoints as different characters
													__SCREAMING_SNAKE_CASE     :Tuple	       =						unicodedata.normalize('''NFC'''	,SCREAMING_SNAKE_CASE__							)
													__SCREAMING_SNAKE_CASE     :List[Any]	       =						whitespace_tokenize(SCREAMING_SNAKE_CASE__							)
													__SCREAMING_SNAKE_CASE     :Dict	       =						[]
													for token in orig_tokens:
																			if token not in never_split:
																									if self.do_lower_case:
																															__SCREAMING_SNAKE_CASE     :str	       =						token.lower()
																															if self.strip_accents is not False:
																																					__SCREAMING_SNAKE_CASE     :Dict	       =						self._run_strip_accents(SCREAMING_SNAKE_CASE__							)
																									elif self.strip_accents:
																															__SCREAMING_SNAKE_CASE     :Any	       =						self._run_strip_accents(SCREAMING_SNAKE_CASE__							)
																			split_tokens.extend(self._run_split_on_punc(SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__							)							)

													__SCREAMING_SNAKE_CASE     :List[Any]	       =						whitespace_tokenize(''' '''.join(SCREAMING_SNAKE_CASE__							)							)
													return output_tokens




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__							)    ->   List[str]:





													"""simple docstring"""






													__SCREAMING_SNAKE_CASE     :List[str]	       =						unicodedata.normalize('''NFD'''	,SCREAMING_SNAKE_CASE__							)
													__SCREAMING_SNAKE_CASE     :List[str]	       =						[]
													for char in text:
																			__SCREAMING_SNAKE_CASE     :Tuple	       =						unicodedata.category(SCREAMING_SNAKE_CASE__							)
																			if cat == "Mn":
																									continue
																			output.append(SCREAMING_SNAKE_CASE__							)
													return "".join(SCREAMING_SNAKE_CASE__							)




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__=None							)    ->   Optional[Any]:





													"""simple docstring"""






													if not self.do_split_on_punc or (never_split is not None and text in never_split):
																			return [text]
													__SCREAMING_SNAKE_CASE     :Tuple	       =						list(SCREAMING_SNAKE_CASE__							)
													__SCREAMING_SNAKE_CASE     :List[Any]	       =						0
													__SCREAMING_SNAKE_CASE     :str	       =						True
													__SCREAMING_SNAKE_CASE     :Any	       =						[]
													while i < len(SCREAMING_SNAKE_CASE__							):
																			__SCREAMING_SNAKE_CASE     :Dict	       =						chars[i]
																			if _is_punctuation(SCREAMING_SNAKE_CASE__							):
																									output.append([char]							)
																									__SCREAMING_SNAKE_CASE     :str	       =						True
																			else:
																									if start_new_word:
																															output.append([]							)
																									__SCREAMING_SNAKE_CASE     :str	       =						False
																									output[-1].append(SCREAMING_SNAKE_CASE__							)
																			i += 1

													return ["".join(SCREAMING_SNAKE_CASE__							) for x in output]




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__							)    ->   Tuple:





													"""simple docstring"""






													__SCREAMING_SNAKE_CASE     :str	       =						[]
													for char in text:
																			__SCREAMING_SNAKE_CASE     :int	       =						ord(SCREAMING_SNAKE_CASE__							)
																			if self._is_chinese_char(SCREAMING_SNAKE_CASE__							):
																									output.append(''' '''							)
																									output.append(SCREAMING_SNAKE_CASE__							)
																									output.append(''' '''							)
																			else:
																									output.append(SCREAMING_SNAKE_CASE__							)
													return "".join(SCREAMING_SNAKE_CASE__							)




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__							)    ->   Tuple:





													"""simple docstring"""






													if (
													    (cp >= 0x4_e00 and cp <= 0x9_fff)
													    or (cp >= 0x3_400 and cp <= 0x4_dbf)  #
													    or (cp >= 0x20_000 and cp <= 0x2a_6df)  #
													    or (cp >= 0x2a_700 and cp <= 0x2b_73f)  #
													    or (cp >= 0x2b_740 and cp <= 0x2b_81f)  #
													    or (cp >= 0x2b_820 and cp <= 0x2c_eaf)  #
													    or (cp >= 0xf_900 and cp <= 0xf_aff)
													    or (cp >= 0x2f_800 and cp <= 0x2f_a1f)  #
													):  #
																			return True

													return False




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__							)    ->   Union[str, Any]:





													"""simple docstring"""






													__SCREAMING_SNAKE_CASE     :Dict	       =						[]
													for char in text:
																			__SCREAMING_SNAKE_CASE     :List[Any]	       =						ord(SCREAMING_SNAKE_CASE__							)
																			if cp == 0 or cp == 0xf_ffd or _is_control(SCREAMING_SNAKE_CASE__							):
																									continue
																			if _is_whitespace(SCREAMING_SNAKE_CASE__							):
																									output.append(''' '''							)
																			else:
																									output.append(SCREAMING_SNAKE_CASE__							)
													return "".join(SCREAMING_SNAKE_CASE__							)




def   __lowerCamelCase     (							a_  :	Union[str, Any]							)    ->   Optional[int]:
						__SCREAMING_SNAKE_CASE     :int	       =						set()
						__SCREAMING_SNAKE_CASE     :Dict	       =						word[0]
						for char in word[1:]:
												pairs.add((prev_char, char)							)
												__SCREAMING_SNAKE_CASE     :Optional[int]	       =						char
						return pairs



def   __lowerCamelCase     (							a_  :	Union[str, Any]							)    ->   int:
						__SCREAMING_SNAKE_CASE     :Tuple	       =						text.replace('''—'''				,     '''-'''							)
						__SCREAMING_SNAKE_CASE     :Union[str, Any]	       =						text.replace('''–'''				,     '''-'''							)
						__SCREAMING_SNAKE_CASE     :Optional[Any]	       =						text.replace('''―'''				,     '''-'''							)
						__SCREAMING_SNAKE_CASE     :str	       =						text.replace('''…'''				,     '''...'''							)
						__SCREAMING_SNAKE_CASE     :Tuple	       =						text.replace('''´'''				,     '''\''''							)
						__SCREAMING_SNAKE_CASE     :List[Any]	       =						re.sub(r'''(-+|~+|!+|"+|;+|\?+|\++|,+|\)+|\(+|\\+|\/+|\*+|\[+|\]+|}+|{+|\|+|_+)'''				,     r''' \1 '''				,     a_							)
						__SCREAMING_SNAKE_CASE     :List[str]	       =						re.sub(r'''\s*\n\s*'''				,     ''' \n '''				,     a_							)
						__SCREAMING_SNAKE_CASE     :Dict	       =						re.sub(r'''[^\S\n]+'''				,     ''' '''				,     a_							)
						return text.strip()







class       _SCREAMING_SNAKE_CASE(     A						):
							SCREAMING_SNAKE_CASE_     :   Union[str, Any]					=						VOCAB_FILES_NAMES
							SCREAMING_SNAKE_CASE_     :   str					=						PRETRAINED_VOCAB_FILES_MAP
							SCREAMING_SNAKE_CASE_     :   Dict					=						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							SCREAMING_SNAKE_CASE_     :   Tuple					=						['''input_ids''', '''attention_mask''']




							def __init__(		self	,SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__="<unk>"	,**SCREAMING_SNAKE_CASE__							)    ->   List[Any]:





													"""simple docstring"""






													super().__init__(unk_token=SCREAMING_SNAKE_CASE__	,**SCREAMING_SNAKE_CASE__							)

													try:
																			import ftfy
																			from spacy.lang.en import English

																			__SCREAMING_SNAKE_CASE     :Union[str, Any]	       =						English()
																			__SCREAMING_SNAKE_CASE     :Dict	       =						_nlp.tokenizer
																			__SCREAMING_SNAKE_CASE     :Optional[Any]	       =						ftfy.fix_text
													except ImportError:
																			logger.warning('''ftfy or spacy is not installed using BERT BasicTokenizer instead of SpaCy & ftfy.'''							)
																			__SCREAMING_SNAKE_CASE     :Optional[Any]	       =						BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__							)
																			__SCREAMING_SNAKE_CASE     :Optional[int]	       =						None

													with open(SCREAMING_SNAKE_CASE__	,encoding='''utf-8'''							) as vocab_handle:
																			__SCREAMING_SNAKE_CASE     :Any	       =						json.load(SCREAMING_SNAKE_CASE__							)
													__SCREAMING_SNAKE_CASE     :Optional[int]	       =						{v: k for k, v in self.encoder.items()}
													with open(SCREAMING_SNAKE_CASE__	,encoding='''utf-8'''							) as merges_handle:
																			__SCREAMING_SNAKE_CASE     :int	       =						merges_handle.read().split('''\n'''							)[1:-1]
													__SCREAMING_SNAKE_CASE     :List[str]	       =						[tuple(merge.split()							) for merge in merges]
													__SCREAMING_SNAKE_CASE     :Any	       =						dict(zip(SCREAMING_SNAKE_CASE__	,range(len(SCREAMING_SNAKE_CASE__							)							)							)							)
													__SCREAMING_SNAKE_CASE     :Tuple	       =						{}




							@property
							def 					_UpperCamelCase  (		self							)    ->   Dict:





													"""simple docstring"""






													return True




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





													"""simple docstring"""






													return len(self.encoder							)




							def 					_UpperCamelCase  (		self							)    ->   List[Any]:





													"""simple docstring"""






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




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__							)    ->   Union[str, Any]:





													"""simple docstring"""






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

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

													while True:
																			__SCREAMING_SNAKE_CASE     :List[str]	       =						min(SCREAMING_SNAKE_CASE__	,key=lambda SCREAMING_SNAKE_CASE__							: self.bpe_ranks.get(SCREAMING_SNAKE_CASE__	,float('''inf'''							)							)							)
																			if bigram not in self.bpe_ranks:
																									break
																			__SCREAMING_SNAKE_CASE     :Dict	       =						bigram
																			__SCREAMING_SNAKE_CASE     :Dict	       =						[]
																			__SCREAMING_SNAKE_CASE     :Union[str, Any]	       =						0
																			while i < len(SCREAMING_SNAKE_CASE__							):
																									try:
																															__SCREAMING_SNAKE_CASE     :Tuple	       =						word.index(SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__							)
																									except ValueError:
																															new_word.extend(word[i:]							)
																															break
																									else:
																															new_word.extend(word[i:j]							)
																															__SCREAMING_SNAKE_CASE     :List[str]	       =						j

																									if word[i] == first and i < len(SCREAMING_SNAKE_CASE__							) - 1 and word[i + 1] == second:
																															new_word.append(first + second							)
																															i += 2
																									else:
																															new_word.append(word[i]							)
																															i += 1
																			__SCREAMING_SNAKE_CASE     :str	       =						tuple(SCREAMING_SNAKE_CASE__							)
																			__SCREAMING_SNAKE_CASE     :Any	       =						new_word
																			if len(SCREAMING_SNAKE_CASE__							) == 1:
																									break
																			else:
																									__SCREAMING_SNAKE_CASE     :Optional[Any]	       =						get_pairs(SCREAMING_SNAKE_CASE__							)
													__SCREAMING_SNAKE_CASE     :Dict	       =						''' '''.join(SCREAMING_SNAKE_CASE__							)
													if word == "\n  </w>":
																			__SCREAMING_SNAKE_CASE     :Tuple	       =						'''\n</w>'''
													__SCREAMING_SNAKE_CASE     :Optional[int]	       =						word
													return word




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__							)    ->   List[Any]:





													"""simple docstring"""






													__SCREAMING_SNAKE_CASE     :int	       =						[]
													if self.fix_text is None:
																			# Using BERT's BasicTokenizer
																			__SCREAMING_SNAKE_CASE     :str	       =						self.nlp.tokenize(SCREAMING_SNAKE_CASE__							)
																			for token in text:
																									split_tokens.extend(list(self.bpe(SCREAMING_SNAKE_CASE__							).split(''' '''							)							)							)
													else:
																			# Using SpaCy & ftfy (original tokenization process of OpenAI GPT)
																			__SCREAMING_SNAKE_CASE     :Optional[Any]	       =						self.nlp(text_standardize(self.fix_text(SCREAMING_SNAKE_CASE__							)							)							)
																			for token in text:
																									split_tokens.extend(list(self.bpe(token.text.lower()							).split(''' '''							)							)							)
													return split_tokens




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__							)    ->   Any:





													"""simple docstring"""






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




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__							)    ->   Optional[Any]:





													"""simple docstring"""






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




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__							)    ->   Optional[int]:





													"""simple docstring"""






													__SCREAMING_SNAKE_CASE     :Optional[int]	       =						''''''.join(SCREAMING_SNAKE_CASE__							).replace('''</w>'''	,''' '''							).strip()
													return out_string




							def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__ = None							)    ->   Tuple[str]:





													"""simple docstring"""






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

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

													__SCREAMING_SNAKE_CASE     :Optional[Any]	       =						0
													with open(SCREAMING_SNAKE_CASE__	,'''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 SCREAMING_SNAKE_CASE__							: 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     :Dict	       =						token_index
																									writer.write(''' '''.join(SCREAMING_SNAKE_CASE__							) + '''\n'''							)
																									index += 1

													return vocab_file, merge_file






"""simple docstring"""
def   __lowerCamelCase     (							a_  :	int = 10**6							)    ->   int:

      if n <= 0:
            raise ValueError('''Please enter an integer greater than 0'''							)

      __SCREAMING_SNAKE_CASE     :Tuple	       =						list(range(n + 1							)							)
      for number in range(2				,     n + 1							):
            if phi[number] == number:
                  phi[number] -= 1
                  for multiple in range(number * 2				,     n + 1				,     a_							):
                        __SCREAMING_SNAKE_CASE     :List[Any]	       =						(phi[multiple] // number) * (number - 1)

      __SCREAMING_SNAKE_CASE     :Optional[Any]	       =						1
      for number in range(1				,     n + 1							):
            if (answer / phi[answer]) < (number / phi[number]):
                  __SCREAMING_SNAKE_CASE     :str	       =						number

      return answer


if __name__ == "__main__":
  print(solution())