





'''simple docstring'''







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


snake_case_   :				int		=     logging.get_logger(__name__)


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

# See all BART models at https://huggingface.co/models?filter=bart
snake_case_   :				List[str]		=     {
    "vocab_file": {
        "facebook/bart-base": "https://huggingface.co/facebook/bart-base/resolve/main/vocab.json",
        "facebook/bart-large": "https://huggingface.co/facebook/bart-large/resolve/main/vocab.json",
        "facebook/bart-large-mnli": "https://huggingface.co/facebook/bart-large-mnli/resolve/main/vocab.json",
        "facebook/bart-large-cnn": "https://huggingface.co/facebook/bart-large-cnn/resolve/main/vocab.json",
        "facebook/bart-large-xsum": "https://huggingface.co/facebook/bart-large-xsum/resolve/main/vocab.json",
        "yjernite/bart_eli5": "https://huggingface.co/yjernite/bart_eli5/resolve/main/vocab.json",
    },
    "merges_file": {
        "facebook/bart-base": "https://huggingface.co/facebook/bart-base/resolve/main/merges.txt",
        "facebook/bart-large": "https://huggingface.co/facebook/bart-large/resolve/main/merges.txt",
        "facebook/bart-large-mnli": "https://huggingface.co/facebook/bart-large-mnli/resolve/main/merges.txt",
        "facebook/bart-large-cnn": "https://huggingface.co/facebook/bart-large-cnn/resolve/main/merges.txt",
        "facebook/bart-large-xsum": "https://huggingface.co/facebook/bart-large-xsum/resolve/main/merges.txt",
        "yjernite/bart_eli5": "https://huggingface.co/yjernite/bart_eli5/resolve/main/merges.txt",
    },
}

snake_case_   :				Optional[Any]		=     {
    "facebook/bart-base": 10_24,
    "facebook/bart-large": 10_24,
    "facebook/bart-large-mnli": 10_24,
    "facebook/bart-large-cnn": 10_24,
    "facebook/bart-large-xsum": 10_24,
    "yjernite/bart_eli5": 10_24,
}





@lru_cache()
def 				lowerCamelCase_					(     )       ->		Optional[int]:
						UpperCAmelCase_	:					Any     =     (
						    list(range(ord('''!'''      ),	ord('''~'''      ) + 1      )      ) + list(range(ord('''¡'''      ),	ord('''¬'''      ) + 1      )      ) + list(range(ord('''®'''      ),	ord('''ÿ'''      ) + 1      )      )
						)
						UpperCAmelCase_	:					Optional[Any]     =     bs[:]
						UpperCAmelCase_	:					Union[str, Any]     =     0
						for b in range(2**8      ):
												if b not in bs:
																		bs.append(SCREAMING_SNAKE_CASE__      )
																		cs.append(2**8 + n      )
																		n += 1
						UpperCAmelCase_	:					Dict     =     [chr(SCREAMING_SNAKE_CASE__      ) for n in cs]
						return dict(zip(SCREAMING_SNAKE_CASE__,	SCREAMING_SNAKE_CASE__      )      )





def 				lowerCamelCase_					(     SCREAMING_SNAKE_CASE__					:	Optional[Any]      )       ->		Optional[int]:
						UpperCAmelCase_	:					int     =     set()
						UpperCAmelCase_	:					Dict     =     word[0]
						for char in word[1:]:
												pairs.add((prev_char, char)      )
												UpperCAmelCase_	:					Dict     =     char
						return pairs


class     __a					(lowerCamelCase   ):
							__a    :      Dict  	=				VOCAB_FILES_NAMES
							__a    :      Tuple  	=				PRETRAINED_VOCAB_FILES_MAP
							__a    :      Any  	=				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							__a    :      int  	=				["input_ids", "attention_mask"]

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







													"""simple docstring"""
													UpperCAmelCase_	:					Optional[int]     =     AddedToken(_lowerCAmelCase				,   lstrip=_lowerCAmelCase				,   rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase				,   _lowerCAmelCase      ) else bos_token
													UpperCAmelCase_	:					Optional[Any]     =     AddedToken(_lowerCAmelCase				,   lstrip=_lowerCAmelCase				,   rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase				,   _lowerCAmelCase      ) else eos_token
													UpperCAmelCase_	:					Union[str, Any]     =     AddedToken(_lowerCAmelCase				,   lstrip=_lowerCAmelCase				,   rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase				,   _lowerCAmelCase      ) else sep_token
													UpperCAmelCase_	:					Dict     =     AddedToken(_lowerCAmelCase				,   lstrip=_lowerCAmelCase				,   rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase				,   _lowerCAmelCase      ) else cls_token
													UpperCAmelCase_	:					int     =     AddedToken(_lowerCAmelCase				,   lstrip=_lowerCAmelCase				,   rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase				,   _lowerCAmelCase      ) else unk_token
													UpperCAmelCase_	:					List[Any]     =     AddedToken(_lowerCAmelCase				,   lstrip=_lowerCAmelCase				,   rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase				,   _lowerCAmelCase      ) else pad_token

													# Mask token behave like a normal word, i.e. include the space before it
													UpperCAmelCase_	:					Union[str, Any]     =     AddedToken(_lowerCAmelCase				,   lstrip=_lowerCAmelCase				,   rstrip=_lowerCAmelCase      ) if isinstance(_lowerCAmelCase				,   _lowerCAmelCase      ) else mask_token

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

													with open(_lowerCAmelCase				,   encoding='''utf-8'''      ) as vocab_handle:
																			UpperCAmelCase_	:					Optional[int]     =     json.load(_lowerCAmelCase      )
													UpperCAmelCase_	:					List[str]     =     {v: k for k, v in self.encoder.items()}
													UpperCAmelCase_	:					Tuple     =     errors  # how to handle errors in decoding
													UpperCAmelCase_	:					Any     =     bytes_to_unicode()
													UpperCAmelCase_	:					Any     =     {v: k for k, v in self.byte_encoder.items()}
													with open(_lowerCAmelCase				,   encoding='''utf-8'''      ) as merges_handle:
																			UpperCAmelCase_	:					Tuple     =     merges_handle.read().split('''\n'''      )[1:-1]
													UpperCAmelCase_	:					Optional[int]     =     [tuple(merge.split()      ) for merge in bpe_merges]
													UpperCAmelCase_	:					Dict     =     dict(zip(_lowerCAmelCase				,   range(len(_lowerCAmelCase      )      )      )      )
													UpperCAmelCase_	:					Union[str, Any]     =     {}
													UpperCAmelCase_	:					Any     =     add_prefix_space

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

							@property
							def 			UpperCAmelCase__		(							self							:   Optional[int]      )    ->				Union[str, Any]:







													"""simple docstring"""
													return len(self.encoder      )

							def 			UpperCAmelCase__		(							self							:   int      )    ->				str:







													"""simple docstring"""
													return dict(self.encoder				,   **self.added_tokens_encoder      )

							def 			UpperCAmelCase__		(							self							:   List[str]				,   __magic_name__							:   Dict      )    ->				Tuple:







													"""simple docstring"""
													if token in self.cache:
																			return self.cache[token]
													UpperCAmelCase_	:					List[Any]     =     tuple(_lowerCAmelCase      )
													UpperCAmelCase_	:					Any     =     get_pairs(_lowerCAmelCase      )

													if not pairs:
																			return token

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

																									if word[i] == first and i < len(_lowerCAmelCase      ) - 1 and word[i + 1] == second:
																															new_word.append(first + second      )
																															i += 2
																									else:
																															new_word.append(word[i]      )
																															i += 1
																			UpperCAmelCase_	:					Any     =     tuple(_lowerCAmelCase      )
																			UpperCAmelCase_	:					Union[str, Any]     =     new_word
																			if len(_lowerCAmelCase      ) == 1:
																									break
																			else:
																									UpperCAmelCase_	:					Any     =     get_pairs(_lowerCAmelCase      )
													UpperCAmelCase_	:					int     =     " ".join(_lowerCAmelCase      )
													UpperCAmelCase_	:					Union[str, Any]     =     word
													return word

							def 			UpperCAmelCase__		(							self							:   Dict				,   __magic_name__							:   Tuple      )    ->				Dict:







													"""simple docstring"""
													UpperCAmelCase_	:					List[Any]     =     []
													for token in re.findall(self.pat				,   _lowerCAmelCase      ):
																			UpperCAmelCase_	:					str     =     "".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(_lowerCAmelCase      ).split(''' '''      )      )
													return bpe_tokens

							def 			UpperCAmelCase__		(							self							:   Tuple				,   __magic_name__							:   List[Any]      )    ->				str:







													"""simple docstring"""
													return self.encoder.get(_lowerCAmelCase				,   self.encoder.get(self.unk_token      )      )

							def 			UpperCAmelCase__		(							self							:   Tuple				,   __magic_name__							:   Dict      )    ->				Union[str, Any]:







													"""simple docstring"""
													return self.decoder.get(_lowerCAmelCase      )

							def 			UpperCAmelCase__		(							self							:   Union[str, Any]				,   __magic_name__							:   Optional[int]      )    ->				str:







													"""simple docstring"""
													UpperCAmelCase_	:					str     =     "".join(_lowerCAmelCase      )
													UpperCAmelCase_	:					str     =     bytearray([self.byte_decoder[c] for c in text]      ).decode('''utf-8'''				,   errors=self.errors      )
													return text

							def 			UpperCAmelCase__		(							self							:   str				,   __magic_name__							:   str				,   __magic_name__							:   Optional[str] = None      )    ->				Optional[Any]:







													"""simple docstring"""
													if not os.path.isdir(_lowerCAmelCase      ):
																			logger.error(F"""Vocabulary path ({save_directory}) should be a directory"""      )
																			return
													UpperCAmelCase_	:					Tuple     =     os.path.join(
													    _lowerCAmelCase				,   (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']      )
													UpperCAmelCase_	:					str     =     os.path.join(
													    _lowerCAmelCase				,   (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''merges_file''']      )

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

													UpperCAmelCase_	:					int     =     0
													with open(_lowerCAmelCase				,   '''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 __magic_name__      : 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_	:					Tuple     =     token_index
																									writer.write(''' '''.join(_lowerCAmelCase      ) + '''\n'''      )
																									index += 1

													return vocab_file, merge_file

							def 			UpperCAmelCase__		(							self							:   Optional[int]				,   __magic_name__							:   List[int]				,   __magic_name__							:   Optional[List[int]] = None      )    ->				Union[str, Any]:







													"""simple docstring"""
													if token_ids_a is None:
																			return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
													UpperCAmelCase_	:					Any     =     [self.cls_token_id]
													UpperCAmelCase_	:					Optional[int]     =     [self.sep_token_id]
													return cls + token_ids_a + sep + sep + token_ids_a + sep

							def 			UpperCAmelCase__		(							self							:   List[Any]				,   __magic_name__							:   List[int]				,   __magic_name__							:   Optional[List[int]] = None				,   __magic_name__							:   bool = False      )    ->				Optional[Any]:







													"""simple docstring"""
													if already_has_special_tokens:
																			return super().get_special_tokens_mask(
																			    token_ids_a=_lowerCAmelCase				,   token_ids_a=_lowerCAmelCase				,   already_has_special_tokens=_lowerCAmelCase      )

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

							def 			UpperCAmelCase__		(							self							:   Union[str, Any]				,   __magic_name__							:   List[int]				,   __magic_name__							:   Optional[List[int]] = None      )    ->				Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_	:					Union[str, Any]     =     [self.sep_token_id]
													UpperCAmelCase_	:					Optional[int]     =     [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 			UpperCAmelCase__		(							self							:   int				,   __magic_name__							:   str				,   __magic_name__							:   str=False				,   **__magic_name__							:   str      )    ->				Dict:







													"""simple docstring"""
													UpperCAmelCase_	:					Dict     =     kwargs.pop('''add_prefix_space'''				,   self.add_prefix_space      )
													if (is_split_into_words or add_prefix_space) and (len(_lowerCAmelCase      ) > 0 and not text[0].isspace()):
																			UpperCAmelCase_	:					Any     =     " " + text
													return (text, kwargs)











import math
import sys



def 					UpperCAmelCase__     (   lowerCamelCase      ):
  if number != int(lowerCamelCase      ):
    raise ValueError("the value of input must be a natural number"      )
  if number < 0:
    raise ValueError("the value of input must not be a negative number"      )
  if number == 0:
    return 1
  lowercase			:Dict							=  [-1] * (number + 1)
  lowercase			:Optional[Any]							=  0
  for i in range(1,	number + 1      ):
    lowercase			:Optional[int]							=  sys.maxsize
    lowercase			:Any							=  int(math.sqrt(lowerCamelCase      )      )
    for j in range(1,	root + 1      ):
      lowercase			:Any							=  1 + answers[i - (j**2)]
      lowercase			:Dict							=  min(lowerCamelCase,	lowerCamelCase      )
    lowercase			:Union[str, Any]							=  answer
  return answers[number]


if __name__ == "__main__":
     import doctest

     doctest.testmod()



