





"""simple docstring"""




lowerCamelCase_     :						Union[str, Any]						=					range(2, 20 + 1)
lowerCamelCase_     :						Dict						=					[10**k for k in range(ks[-1] + 1)]
lowerCamelCase_     :						dict[int, dict[int, list[list[int]]]]						=					{}





def 						UpperCAmelCase__		(     _UpperCAmelCase ,					_UpperCAmelCase ,					_UpperCAmelCase ,					_UpperCAmelCase					):






  """simple docstring"""





  A_  :       List[str]										=  sum(a_i[j] for j in range(_UpperCAmelCase ,					len(_UpperCAmelCase					)					)					)
  A_  :       Any										=  sum(a_i[j] * base[j] for j in range(min(len(_UpperCAmelCase					) ,					_UpperCAmelCase					)					)					)

  A_						,       A_  :       List[Any]										=  0, 0
  A_  :       List[Any]										=  n - i

  A_  :       Optional[Any]										=  memo.get(_UpperCAmelCase					)

  if sub_memo is not None:
    A_  :       Union[str, Any]										=  sub_memo.get(_UpperCAmelCase					)

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

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

    else:
      A_  :       str										=  []
  else:
    A_  :       List[str]										=  {c: []}
    A_  :       Union[str, 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
      A_						,       A_  :       Optional[int]										=  next_term(_UpperCAmelCase ,					k - 1 ,					i + dn ,					_UpperCAmelCase					)
      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
    A_						,       A_  :       Optional[int]										=  compute(_UpperCAmelCase ,					_UpperCAmelCase ,					i + dn ,					_UpperCAmelCase					)
    diff += _diff
    dn += terms_jumped

  A_  :       Optional[int]										=  sub_memo[c]

  # keep jumps sorted by # of terms skipped
  A_  :       Optional[int]										=  0
  while j < len(_UpperCAmelCase					):
    if jumps[j][1] > dn:
      break
    j += 1

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





def 						UpperCAmelCase__		(     _UpperCAmelCase ,					_UpperCAmelCase ,					_UpperCAmelCase ,					_UpperCAmelCase					):






  """simple docstring"""





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

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

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

      ds_c += a_i[j]

    if addend > 0:
      break

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





def 						UpperCAmelCase__		(     _UpperCAmelCase ,					_UpperCAmelCase ,					_UpperCAmelCase					):






  """simple docstring"""





  for j in range(_UpperCAmelCase ,					len(_UpperCAmelCase					)					):
    A_  :       Dict										=  digits[j] + addend
    if s >= 10:
      A_						,       A_  :       Union[str, Any]										=  divmod(_UpperCAmelCase ,					10					)
      A_  :       Dict										=  addend // 10 + quotient
    else:
      A_  :       int										=  s
      A_  :       Any										=  addend // 10

    if addend == 0:
      break

  while addend > 0:
    A_						,       A_  :       Any										=  divmod(_UpperCAmelCase ,					10					)
    digits.append(_UpperCAmelCase					)





def 						UpperCAmelCase__		(     _UpperCAmelCase = 10**15					):






  """simple docstring"""





  A_  :       str										=  [1]
  A_  :       Any										=  1
  A_  :       Dict										=  0
  while True:
    A_						,       A_  :       Optional[int]										=  next_term(_UpperCAmelCase ,					20 ,					i + dn ,					_UpperCAmelCase					)
    dn += terms_jumped
    if dn == n - i:
      break

  A_  :       Any										=  0
  for j in range(len(_UpperCAmelCase					)					):
    a_n += digits[j] * 10**j
  return a_n


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






"""simple docstring"""




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available


lowerCamelCase_     :						int						=					{}


try:
   if not is_sentencepiece_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCamelCase_     :						Tuple						=					['MLukeTokenizer']

if TYPE_CHECKING:
   try:
      if not is_sentencepiece_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_mluke import MLukeTokenizer


else:
   import sys

   lowerCamelCase_     :						List[str]						=					_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)