




import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_funnel import FunnelTokenizer


lowerCAmelCase_						=			logging.get_logger(__name__)

lowerCAmelCase_						=			{'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

lowerCAmelCase_						=			[
    'small',
    'small-base',
    'medium',
    'medium-base',
    'intermediate',
    'intermediate-base',
    'large',
    'large-base',
    'xlarge',
    'xlarge-base',
]

lowerCAmelCase_						=			{
    'vocab_file': {
        'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/vocab.txt',
        'funnel-transformer/small-base': 'https://huggingface.co/funnel-transformer/small-base/resolve/main/vocab.txt',
        'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/vocab.txt',
        'funnel-transformer/medium-base': (
            'https://huggingface.co/funnel-transformer/medium-base/resolve/main/vocab.txt'
        ),
        'funnel-transformer/intermediate': (
            'https://huggingface.co/funnel-transformer/intermediate/resolve/main/vocab.txt'
        ),
        'funnel-transformer/intermediate-base': (
            'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/vocab.txt'
        ),
        'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/vocab.txt',
        'funnel-transformer/large-base': 'https://huggingface.co/funnel-transformer/large-base/resolve/main/vocab.txt',
        'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/vocab.txt',
        'funnel-transformer/xlarge-base': (
            'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/tokenizer.json',
        'funnel-transformer/small-base': (
            'https://huggingface.co/funnel-transformer/small-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/tokenizer.json',
        'funnel-transformer/medium-base': (
            'https://huggingface.co/funnel-transformer/medium-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/intermediate': (
            'https://huggingface.co/funnel-transformer/intermediate/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/intermediate-base': (
            'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/tokenizer.json',
        'funnel-transformer/large-base': (
            'https://huggingface.co/funnel-transformer/large-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/tokenizer.json',
        'funnel-transformer/xlarge-base': (
            'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/tokenizer.json'
        ),
    },
}
lowerCAmelCase_						=			{f'''funnel-transformer/{name}''': 5_12 for name in _model_names}
lowerCAmelCase_						=			{f'''funnel-transformer/{name}''': {'do_lower_case': True} for name in _model_names}
class 						_A (  _lowerCamelCase				):
  _UpperCamelCase       :      Any			=      VOCAB_FILES_NAMES
  _UpperCamelCase       :      str			=      PRETRAINED_VOCAB_FILES_MAP
  _UpperCamelCase       :      Optional[Any]			=      PRETRAINED_INIT_CONFIGURATION
  _UpperCamelCase       :      Union[str, Any]			=      FunnelTokenizer
  _UpperCamelCase       :      Dict			=      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  _UpperCamelCase       :      int			=      2






  def __init__(  self		:     List[Any]				,						_A		:     Union[str, Any]=None				,						_A		:     List[Any]=None				,						_A		:     Optional[int]=True				,						_A		:     Dict="<unk>"				,						_A		:     Optional[int]="<sep>"				,						_A		:     Tuple="<pad>"				,						_A		:     Union[str, Any]="<cls>"				,						_A		:     Dict="<mask>"				,						_A		:     List[Any]="<s>"				,						_A		:     Dict="</s>"				,						_A		:     Tuple=True				,						_A		:     Dict=True				,						_A		:     int=None				,						_A		:     List[Any]="##"				,						**_A		:     int				,						)		->   Optional[int]:






       """simple docstring"""







       super().__init__(
           _A				,						tokenizer_file=_A				,						do_lower_case=_A				,						unk_token=_A				,						sep_token=_A				,						pad_token=_A				,						cls_token=_A				,						mask_token=_A				,						bos_token=_A				,						eos_token=_A				,						clean_text=_A				,						tokenize_chinese_chars=_A				,						strip_accents=_A				,						wordpieces_prefix=_A				,						**_A				,						)

       lowercase :       Tuple       =			json.loads(self.backend_tokenizer.normalizer.__getstate__()				)
       if (
           normalizer_state.get('''lowercase'''				,						_A				) != do_lower_case
           or normalizer_state.get('''strip_accents'''				,						_A				) != strip_accents
           or normalizer_state.get('''handle_chinese_chars'''				,						_A				) != tokenize_chinese_chars
       ):
            lowercase :       Union[str, Any]       =			getattr(_A				,						normalizer_state.pop('''type'''				)				)
            lowercase :       int       =			do_lower_case
            lowercase :       Optional[int]       =			strip_accents
            lowercase :       str       =			tokenize_chinese_chars
            lowercase :       Dict       =			normalizer_class(**_A				)

       lowercase :       int       =			do_lower_case






  def  __a      (  self		:     int				,						_A		:     Optional[Any]				,						_A		:     Union[str, Any]=None				)		->   Optional[int]:






       """simple docstring"""







       lowercase :       int       =			[self.cls_token_id] + token_ids_a + [self.sep_token_id]

       if token_ids_a:
            output += token_ids_a + [self.sep_token_id]

       return output






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






       """simple docstring"""







       lowercase :       Tuple       =			[self.sep_token_id]
       lowercase :       Optional[int]       =			[self.cls_token_id]
       if token_ids_a is None:
            return len(cls				) * [self.cls_token_type_id] + len(token_ids_a + sep				) * [0]
       return len(cls				) * [self.cls_token_type_id] + len(token_ids_a + sep				) * [0] + len(token_ids_a + sep				) * [1]






  def  __a      (  self		:     Dict				,						_A		:     str				,						_A		:     Optional[str] = None				)		->   Tuple[str]:






       """simple docstring"""







       lowercase :       List[str]       =			self._tokenizer.model.save(_A				,						name=_A				)
       return tuple(_A				)





lowerCAmelCase_						=			range(2, 20 + 1)
lowerCAmelCase_						=			[10**k for k in range(ks[-1] + 1)]
lowerCAmelCase_						=			{}






def  snake_case(    __magic_name__			,		__magic_name__			,		__magic_name__			,		__magic_name__   )			->							Any:





     '''simple docstring'''


     lowercase :       str       =			sum(a_i[j] for j in range(__magic_name__			,		len(__magic_name__   )   )   )
     lowercase :       Any       =			sum(a_i[j] * base[j] for j in range(min(len(__magic_name__   )			,		__magic_name__   )   )   )

     lowercase      ,	lowercase :       Optional[int]       =			0, 0
     lowercase :       str       =			n - i

     lowercase :       Optional[int]       =			memo.get(__magic_name__   )

     if sub_memo is not None:
          lowercase :       List[str]       =			sub_memo.get(__magic_name__   )

          if jumps is not None and len(__magic_name__   ) > 0:
               # find and make the largest jump without going over
               lowercase :       Dict       =			-1
               for _k in range(len(__magic_name__   ) - 1			,		-1			,		-1   ):
                    if jumps[_k][2] <= k and jumps[_k][1] <= max_dn:
                         lowercase :       Any       =			_k
                         break

               if max_jump >= 0:
                    lowercase      ,	lowercase      ,	lowercase :       List[str]       =			jumps[max_jump]
                    # since the difference between jumps is cached, add c
                    lowercase :       str       =			diff + c
                    for j in range(min(__magic_name__			,		len(__magic_name__   )   )   ):
                         lowercase      ,	lowercase :       Optional[Any]       =			divmod(__magic_name__			,		10   )
                    if new_c > 0:
                         add(__magic_name__			,		__magic_name__			,		__magic_name__   )

          else:
               lowercase :       Dict       =			[]
     else:
          lowercase :       Union[str, Any]       =			{c: []}
          lowercase :       Optional[Any]       =			sub_memo

     if dn >= max_dn or c + diff >= base[k]:
          return diff, dn

     if k > ks[0]:
          while True:
               # keep doing smaller jumps
               lowercase      ,	lowercase :       str       =			next_term(__magic_name__			,		k - 1			,		i + dn			,		__magic_name__   )
               diff += _diff
               dn += terms_jumped

               if dn >= max_dn or c + diff >= base[k]:
                    break
     else:
          # would be too small a jump, just compute sequential terms instead
          lowercase      ,	lowercase :       Optional[Any]       =			compute(__magic_name__			,		__magic_name__			,		i + dn			,		__magic_name__   )
          diff += _diff
          dn += terms_jumped

     lowercase :       Optional[Any]       =			sub_memo[c]

     # keep jumps sorted by # of terms skipped
     lowercase :       List[Any]       =			0
     while j < len(__magic_name__   ):
          if jumps[j][1] > dn:
               break
          j += 1

     # cache the jump for this value digitsum(b) and c
     sub_memo[c].insert(__magic_name__			,		(diff, dn, k)   )
     return (diff, dn)






def  snake_case(    __magic_name__			,		__magic_name__			,		__magic_name__			,		__magic_name__   )			->							Optional[int]:





     '''simple docstring'''


     if i >= n:
          return 0, i
     if k > len(__magic_name__   ):
          a_i.extend([0 for _ in range(k - len(__magic_name__   )   )]   )

     # note: a_i -> b * 10^k + c
     # ds_b -> digitsum(b)
     # ds_c -> digitsum(c)
     lowercase :       Optional[Any]       =			i
     lowercase      ,	lowercase      ,	lowercase :       List[str]       =			0, 0, 0
     for j in range(len(__magic_name__   )   ):
          if j >= k:
               ds_b += a_i[j]
          else:
               ds_c += a_i[j]

     while i < n:
          i += 1
          lowercase :       List[str]       =			ds_c + ds_b
          diff += addend
          lowercase :       Tuple       =			0
          for j in range(__magic_name__   ):
               lowercase :       int       =			a_i[j] + addend
               lowercase      ,	lowercase :       Any       =			divmod(__magic_name__			,		10   )

               ds_c += a_i[j]

          if addend > 0:
               break

     if addend > 0:
          add(__magic_name__			,		__magic_name__			,		__magic_name__   )
     return diff, i - start_i






def  snake_case(    __magic_name__			,		__magic_name__			,		__magic_name__   )			->							Tuple:





     '''simple docstring'''


     for j in range(__magic_name__			,		len(__magic_name__   )   ):
          lowercase :       Any       =			digits[j] + addend
          if s >= 10:
               lowercase      ,	lowercase :       List[str]       =			divmod(__magic_name__			,		10   )
               lowercase :       List[str]       =			addend // 10 + quotient
          else:
               lowercase :       Optional[Any]       =			s
               lowercase :       Tuple       =			addend // 10

          if addend == 0:
               break

     while addend > 0:
          lowercase      ,	lowercase :       str       =			divmod(__magic_name__			,		10   )
          digits.append(__magic_name__   )






def  snake_case(    __magic_name__ = 10**15   )			->							int:





     '''simple docstring'''


     lowercase :       List[Any]       =			[1]
     lowercase :       List[Any]       =			1
     lowercase :       str       =			0
     while True:
          lowercase      ,	lowercase :       str       =			next_term(__magic_name__			,		20			,		i + dn			,		__magic_name__   )
          dn += terms_jumped
          if dn == n - i:
               break

     lowercase :       str       =			0
     for j in range(len(__magic_name__   )   ):
          a_n += digits[j] * 10**j
     return a_n


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