

"""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


__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 					lowerCAmelCase  (   ):
 '''simple docstring'''





 UpperCAmelCase__   :					Dict   				=   (
     list(range(ord("""!""" )							,      ord("""~""" ) + 1 ) ) + list(range(ord("""¡""" )							,      ord("""¬""" ) + 1 ) ) + list(range(ord("""®""" )							,      ord("""ÿ""" ) + 1 ) )
 )
 UpperCAmelCase__   :					List[Any]   				=   bs[:]
 UpperCAmelCase__   :					Optional[int]   				=   0
 for b in range(2**8 ):
  if b not in bs:
   bs.append(__UpperCamelCase )
   cs.append(2**8 + n )
   n += 1
 UpperCAmelCase__   :					Dict   				=   [chr(__UpperCamelCase ) for n in cs]
 return dict(zip(__UpperCamelCase							,      __UpperCamelCase ) )
def 					lowerCAmelCase  (   __UpperCamelCase ):
 '''simple docstring'''





 UpperCAmelCase__   :					List[str]   				=   set()
 UpperCAmelCase__   :					List[str]   				=   word[0]
 for char in word[1:]:
  pairs.add((prev_char, char) )
  UpperCAmelCase__   :					str   				=   char
 return pairs







class        __lowercase     (      __lowerCamelCase   ):
  snake_case_			    =    VOCAB_FILES_NAMES
  snake_case_			    =    PRETRAINED_VOCAB_FILES_MAP
  snake_case_			    =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  snake_case_			    =    ["""input_ids""", """attention_mask"""]

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






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

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

  @property
  def 				__lowercase    (					self						:     int      ):






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

  def 				__lowercase    (					self						:     str      ):






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

  def 				__lowercase    (					self						:     Optional[Any]   ,A						:     List[Any]      ):






   '''simple docstring'''
   if token in self.cache:
    return self.cache[token]
   UpperCAmelCase__   :					int   				=   tuple(A      )
   UpperCAmelCase__   :					Any   				=   get_pairs(A      )

   if not pairs:
    return token

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

  def 				__lowercase    (					self						:     Union[str, Any]   ,A						:     Tuple      ):






   '''simple docstring'''
   UpperCAmelCase__   :					str   				=   []
   for token in re.findall(self.pat   ,A      ):
    UpperCAmelCase__   :					List[Any]   				=   """""".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 				__lowercase    (					self						:     Optional[int]   ,A						:     str      ):






   '''simple docstring'''
   return self.encoder.get(A   ,self.encoder.get(self.unk_token      )      )

  def 				__lowercase    (					self						:     Any   ,A						:     str      ):






   '''simple docstring'''
   return self.decoder.get(A      )

  def 				__lowercase    (					self						:     Any   ,A						:     Dict      ):






   '''simple docstring'''
   UpperCAmelCase__   :					Tuple   				=   """""".join(A      )
   UpperCAmelCase__   :					Optional[Any]   				=   bytearray([self.byte_decoder[c] for c in text]      ).decode("""utf-8"""   ,errors=self.errors      )
   return text

  def 				__lowercase    (					self						:     Dict   ,A						:     str   ,A						:     Optional[str] = None      ):






   '''simple docstring'''
   if not os.path.isdir(A      ):
    logger.error(f"Vocabulary path ({save_directory}) should be a directory"      )
    return
   UpperCAmelCase__   :					List[str]   				=   os.path.join(
       A   ,(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]      )
   UpperCAmelCase__   :					Any   				=   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__   :					Optional[Any]   				=   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__   :					Optional[Any]   				=   token_index
     writer.write(""" """.join(A      ) + """\n"""      )
     index += 1

   return vocab_file, merge_file

  def 				__lowercase    (					self						:     Optional[int]   ,A						:     List[int]   ,A						:     Optional[List[int]] = None      ):






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

  def 				__lowercase    (					self						:     Dict   ,A						:     List[int]   ,A						:     Optional[List[int]] = None   ,A						:     bool = False      ):






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






   '''simple docstring'''
   UpperCAmelCase__   :					str   				=   [self.sep_token_id]
   UpperCAmelCase__   :					Optional[Any]   				=   [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 				__lowercase    (					self						:     List[str]   ,A						:     Dict   ,A						:     Optional[Any]=False   ,**A						:     Optional[Any]      ):






   '''simple docstring'''
   UpperCAmelCase__   :					Any   				=   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__   :					Tuple   				=   """ """ + text
   return (text, kwargs)








"""simple docstring"""




from math import factorial
def 					lowerCAmelCase  (   __UpperCamelCase							,      __UpperCamelCase ):
 '''simple docstring'''





 return factorial(__UpperCamelCase ) / (factorial(__UpperCamelCase ) * factorial(n - r ))
def 					lowerCAmelCase  (   ):
 '''simple docstring'''





 UpperCAmelCase__   :					Any   				=   0

 for i in range(1							,      101 ):
  for j in range(1							,      i + 1 ):
   if combinations(__UpperCamelCase							,      __UpperCamelCase ) > 1e6:
    total += 1
 return total


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





