



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


UpperCAmelCase__  =			logging.get_logger(__name__)


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

# See all MVP models at https://huggingface.co/models?filter=mvp
UpperCAmelCase__  =			{
    "vocab_file": {
        "RUCAIBox/mvp": "https://huggingface.co/RUCAIBox/mvp/resolve/main/vocab.json",
    },
    "added_tokens.json": {
        "RUCAIBox/mvp": "https://huggingface.co/RUCAIBox/mvp/resolve/main/added_tokens.json",
    },
    "merges_file": {
        "RUCAIBox/mvp": "https://huggingface.co/RUCAIBox/mvp/resolve/main/merges.txt",
    },
}

UpperCAmelCase__  =			{
    "RUCAIBox/mvp": 1024,
}





@lru_cache()
def 				A      (	)							->					int:







			'''simple docstring'''
			_UpperCAmelCase									=  (
			    list(range(ord('!'       )				,  ord('~'       ) + 1       )       ) + list(range(ord('¡'       )				,  ord('¬'       ) + 1       )       ) + list(range(ord('®'       )				,  ord('ÿ'       ) + 1       )       )
			)
			_UpperCAmelCase									=  bs[:]
			_UpperCAmelCase									=  0
			for b in range(2**8       ):
						if b not in bs:
									bs.append(_UpperCAmelCase       )
									cs.append(2**8 + n       )
									n += 1
			_UpperCAmelCase									=  [chr(_UpperCAmelCase       ) for n in cs]
			return dict(zip(_UpperCAmelCase				,  _UpperCAmelCase       )       )





def 				A      (	_UpperCAmelCase							:  str       )							->					Dict:







			'''simple docstring'''
			_UpperCAmelCase									=  set()
			_UpperCAmelCase									=  word[0]
			for char in word[1:]:
						pairs.add((prev_char, char)       )
						_UpperCAmelCase									=  char
			return pairs







class      __lowerCAmelCase       (     A		):
			UpperCamelCase     =	VOCAB_FILES_NAMES
			UpperCamelCase     =	PRETRAINED_VOCAB_FILES_MAP
			UpperCamelCase     =	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			UpperCamelCase     =	['''input_ids''', '''attention_mask''']



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



						"""simple docstring"""






						_UpperCAmelCase									=  AddedToken(A					,						lstrip=A					,						rstrip=A) if isinstance(A					,						A) else bos_token
						_UpperCAmelCase									=  AddedToken(A					,						lstrip=A					,						rstrip=A) if isinstance(A					,						A) else eos_token
						_UpperCAmelCase									=  AddedToken(A					,						lstrip=A					,						rstrip=A) if isinstance(A					,						A) else sep_token
						_UpperCAmelCase									=  AddedToken(A					,						lstrip=A					,						rstrip=A) if isinstance(A					,						A) else cls_token
						_UpperCAmelCase									=  AddedToken(A					,						lstrip=A					,						rstrip=A) if isinstance(A					,						A) else unk_token
						_UpperCAmelCase									=  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
						_UpperCAmelCase									=  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:
									_UpperCAmelCase									=  json.load(A)
						_UpperCAmelCase									=  {v: k for k, v in self.encoder.items()}
						_UpperCAmelCase									=  errors  # how to handle errors in decoding
						_UpperCAmelCase									=  bytes_to_unicode()
						_UpperCAmelCase									=  {v: k for k, v in self.byte_encoder.items()}
						with open(A					,						encoding='utf-8') as merges_handle:
									_UpperCAmelCase									=  merges_handle.read().split('\n')[1:-1]
						_UpperCAmelCase									=  [tuple(merge.split()) for merge in bpe_merges]
						_UpperCAmelCase									=  dict(zip(A					,						range(len(A))))
						_UpperCAmelCase									=  {}
						_UpperCAmelCase									=  add_prefix_space

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



			@property
			def        _lowerCamelCase			(		self  :    Union[str, Any])  ->       List[str]:



						"""simple docstring"""






						return len(self.encoder)



			def        _lowerCamelCase			(		self  :    List[str])  ->       List[Any]:



						"""simple docstring"""






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



			def        _lowerCamelCase			(		self  :    Optional[int]					,						A  :    Tuple)  ->       Tuple:



						"""simple docstring"""






						if token in self.cache:
									return self.cache[token]
						_UpperCAmelCase									=  tuple(A)
						_UpperCAmelCase									=  get_pairs(A)

						if not pairs:
									return token

						while True:
									_UpperCAmelCase									=  min(A					,						key=lambda A: self.bpe_ranks.get(A					,						float('inf')))
									if bigram not in self.bpe_ranks:
												break
									_UpperCAmelCase			,	_UpperCAmelCase									=  bigram
									_UpperCAmelCase									=  []
									_UpperCAmelCase									=  0
									while i < len(A):
												try:
															_UpperCAmelCase									=  word.index(A					,						A)
												except ValueError:
															new_word.extend(word[i:])
															break
												else:
															new_word.extend(word[i:j])
															_UpperCAmelCase									=  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
									_UpperCAmelCase									=  tuple(A)
									_UpperCAmelCase									=  new_word
									if len(A) == 1:
												break
									else:
												_UpperCAmelCase									=  get_pairs(A)
						_UpperCAmelCase									=  ' '.join(A)
						_UpperCAmelCase									=  word
						return word



			def        _lowerCamelCase			(		self  :    Any					,						A  :    Optional[int])  ->       int:



						"""simple docstring"""






						_UpperCAmelCase									=  []
						for token in re.findall(self.pat					,						A):
									_UpperCAmelCase									=  ''.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        _lowerCamelCase			(		self  :    Any					,						A  :    List[str])  ->       Tuple:



						"""simple docstring"""






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



			def        _lowerCamelCase			(		self  :    Optional[int]					,						A  :    Tuple)  ->       Tuple:



						"""simple docstring"""






						return self.decoder.get(A)



			def        _lowerCamelCase			(		self  :    Optional[Any]					,						A  :    Dict)  ->       Union[str, Any]:



						"""simple docstring"""






						_UpperCAmelCase									=  ''.join(A)
						_UpperCAmelCase									=  bytearray([self.byte_decoder[c] for c in text]).decode('utf-8'					,						errors=self.errors)
						return text



			def        _lowerCamelCase			(		self  :    Any					,						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
						_UpperCAmelCase									=  os.path.join(
						    A					,						(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file'])
						_UpperCAmelCase									=  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')

						_UpperCAmelCase									=  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!')
															_UpperCAmelCase									=  token_index
												writer.write(' '.join(A) + '\n')
												index += 1

						return vocab_file, merge_file



			def        _lowerCamelCase			(		self  :    str					,						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]
						_UpperCAmelCase									=  [self.cls_token_id]
						_UpperCAmelCase									=  [self.sep_token_id]
						return cls + token_ids_a + sep + sep + token_ids_a + sep



			def        _lowerCamelCase			(		self  :    Tuple					,						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        _lowerCamelCase			(		self  :    List[str]					,						A  :    List[int]					,						A  :    Optional[List[int]] = None)  ->       List[int]:



						"""simple docstring"""






						_UpperCAmelCase									=  [self.sep_token_id]
						_UpperCAmelCase									=  [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        _lowerCamelCase			(		self  :    Any					,						A  :    Tuple					,						A  :    Union[str, Any]=False					,						**A  :    int)  ->       List[Any]:



						"""simple docstring"""






						_UpperCAmelCase									=  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()):
									_UpperCAmelCase									=  ' ' + text
						return (text, kwargs)





import math





def 				A      (	_UpperCAmelCase							:  int       )							->					int:







			'''simple docstring'''
			return sum(int(_UpperCAmelCase       ) for digit in str(_UpperCAmelCase       )       )





def 				A      (	_UpperCAmelCase							:  int = 30       )							->					int:







			'''simple docstring'''
			_UpperCAmelCase									=  []
			for digit in range(2				,  100       ):
						for power in range(2				,  100       ):
									_UpperCAmelCase									=  int(math.pow(_UpperCAmelCase				,  _UpperCAmelCase       )       )
									if digit == digit_sum(_UpperCAmelCase       ):
												digit_to_powers.append(_UpperCAmelCase       )

			digit_to_powers.sort()
			return digit_to_powers[n - 1]


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