


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







def   __lowerCAmelCase						(						lowercase  :  List[Any]						,							lowercase  :  Dict						,							lowercase  :  int						,							lowercase  :  Optional[Any]			)     ->						Union[str, Any]:


    """simple docstring"""





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

    snake_case   :				Any				 =   0, 0
    snake_case   :				Dict				 =   n - i

    snake_case   :				Any				 =   memo.get(lowercase			)

    if sub_memo is not None:
        snake_case   :				int				 =   sub_memo.get(lowercase			)

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

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

        else:
            snake_case   :				Optional[int]				 =   []
    else:
        snake_case   :				Tuple				 =   {c: []}
        snake_case   :				List[str]				 =   sub_memo

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

    if k > ks[0]:
        while True:
            # keep doing smaller jumps
            snake_case   :				List[str]				 =   next_term(lowercase						,							k - 1						,							i + dn						,							lowercase			)
            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
        snake_case   :				Tuple				 =   compute(lowercase						,							lowercase						,							i + dn						,							lowercase			)
        diff += _diff
        dn += terms_jumped

    snake_case   :				Optional[Any]				 =   sub_memo[c]

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

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







def   __lowerCAmelCase						(						lowercase  :  List[str]						,							lowercase  :  List[str]						,							lowercase  :  int						,							lowercase  :  Any			)     ->						Any:


    """simple docstring"""





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

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

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

            ds_c += a_i[j]

        if addend > 0:
            break

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







def   __lowerCAmelCase						(						lowercase  :  List[Any]						,							lowercase  :  int						,							lowercase  :  Union[str, Any]			)     ->						Dict:


    """simple docstring"""





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

        if addend == 0:
            break

    while addend > 0:
        snake_case   :				Optional[int]				 =   divmod(lowercase						,							10			)
        digits.append(lowercase			)







def   __lowerCAmelCase						(						lowercase  :  int = 10**15			)     ->						int:


    """simple docstring"""





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

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


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









"""simple docstring"""



import json
import os
import unittest

from transformers import MgpstrTokenizer
from transformers.models.mgp_str.tokenization_mgp_str import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class _lowerCAmelCase    (				snake_case_   ,							unittest.TestCase     ):
   __UpperCAmelCase			:	List[Any]							  =  MgpstrTokenizer
   __UpperCAmelCase			:	Optional[int]							  =  False
   __UpperCAmelCase			:	Optional[int]							  =  {}
   __UpperCAmelCase			:	List[str]							  =  False







   def 			lowerCamelCase		(     self						)     ->		int:

       '''simple docstring'''




       super().setUp()

       # fmt: off
       snake_case   :				List[str]				 =   ["[GO]", "[s]", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
       # fmt: on
       snake_case   :				Union[str, Any]				 =   dict(zip(UpperCamelCase__						,     range(len(UpperCamelCase__						)						)						)						)

       snake_case   :				int				 =   os.path.join(self.tmpdirname						,     VOCAB_FILES_NAMES["vocab_file"]						)
       with open(self.vocab_file						,     "w"						,     encoding="utf-8"						) as fp:
           fp.write(json.dumps(UpperCamelCase__						) + "\n"						)







   def 			lowerCamelCase		(     self						,     **UpperCamelCase__						)     ->		List[str]:

       '''simple docstring'''




       return MgpstrTokenizer.from_pretrained(self.tmpdirname						,     **UpperCamelCase__						)







   def 			lowerCamelCase		(     self						,     UpperCamelCase__						)     ->		List[Any]:

       '''simple docstring'''




       snake_case   :				int				 =   "tester"
       snake_case   :				List[str]				 =   "tester"
       return input_text, output_text







   @unittest.skip("MGP-STR always lower cases letters."						)
   def 			lowerCamelCase		(     self						)     ->		str:

       '''simple docstring'''




       pass







   def 			lowerCamelCase		(     self						)     ->		Tuple:

       '''simple docstring'''




       snake_case   :				int				 =   self.get_tokenizers(do_lower_case=UpperCamelCase__						)
       for tokenizer in tokenizers:
           with self.subTest(F'{tokenizer.__class__.__name__}'						):
               snake_case   :				List[Any]				 =   "[SPECIAL_TOKEN]"

               tokenizer.add_special_tokens({"cls_token": special_token}						)
               snake_case   :				str				 =   tokenizer.encode([special_token]						,     add_special_tokens=UpperCamelCase__						)
               self.assertEqual(len(UpperCamelCase__						)						,     1						)

               snake_case   :				List[Any]				 =   tokenizer.decode(UpperCamelCase__						,     skip_special_tokens=UpperCamelCase__						)
               self.assertTrue(special_token not in decoded						)







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

       '''simple docstring'''




       snake_case   :				List[str]				 =   self.get_tokenizers()
       for tokenizer in tokenizers:
           with self.subTest(F'{tokenizer.__class__.__name__}'						):
               snake_case ,snake_case   :				Union[str, Any]				 =   self.get_input_output_texts(UpperCamelCase__						)

               snake_case   :				Dict				 =   tokenizer.tokenize(UpperCamelCase__						)
               snake_case   :				Tuple				 =   tokenizer.convert_tokens_to_ids(UpperCamelCase__						)
               snake_case   :				List[Any]				 =   tokenizer.encode(UpperCamelCase__						,     add_special_tokens=UpperCamelCase__						)
               self.assertListEqual(UpperCamelCase__						,     UpperCamelCase__						)

               snake_case   :				Dict				 =   tokenizer.convert_ids_to_tokens(UpperCamelCase__						)
               self.assertNotEqual(len(UpperCamelCase__						)						,     0						)
               snake_case   :				Tuple				 =   tokenizer.decode(UpperCamelCase__						)
               self.assertIsInstance(UpperCamelCase__						,     UpperCamelCase__						)

               self.assertEqual(text_a.replace(" "						,     ""						)						,     UpperCamelCase__						)







   @unittest.skip("MGP-STR tokenizer only handles one sequence."						)
   def 			lowerCamelCase		(     self						)     ->		List[Any]:

       '''simple docstring'''




       pass







   @unittest.skip("inputs cannot be pretokenized in MgpstrTokenizer"						)
   def 			lowerCamelCase		(     self						)     ->		Tuple:

       '''simple docstring'''




       pass





