





'''simple docstring'''




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


     '''simple docstring'''



     _UpperCAmelCase     							=   sum(a_i[j] for j in range(__lowercase			,     len(__lowercase       )       )       )
     _UpperCAmelCase     							=   sum(a_i[j] * base[j] for j in range(min(len(__lowercase       )			,     __lowercase       )       )       )

     _UpperCAmelCase							,  _UpperCAmelCase     							=   0, 0
     _UpperCAmelCase     							=   n - i

     _UpperCAmelCase     							=   memo.get(__lowercase       )

     if sub_memo is not None:
          _UpperCAmelCase     							=   sub_memo.get(__lowercase       )

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

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

          else:
               _UpperCAmelCase     							=   []
     else:
          _UpperCAmelCase     							=   {c: []}
          _UpperCAmelCase     							=   sub_memo

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

     if k > ks[0]:
          while True:
               # keep doing smaller jumps
               _UpperCAmelCase							,  _UpperCAmelCase     							=   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
          _UpperCAmelCase							,  _UpperCAmelCase     							=   compute(__lowercase			,     __lowercase			,     i + dn			,     __lowercase       )
          diff += _diff
          dn += terms_jumped

     _UpperCAmelCase     							=   sub_memo[c]

     # keep jumps sorted by # of terms skipped
     _UpperCAmelCase     							=   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 	UpperCAmelCase_							(					__lowercase							:      Any			,     __lowercase							:      Optional[Any]			,     __lowercase							:      int			,     __lowercase							:      Union[str, Any]       )		->       Optional[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)
     _UpperCAmelCase     							=   i
     _UpperCAmelCase							,  _UpperCAmelCase							,  _UpperCAmelCase     							=   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
          _UpperCAmelCase     							=   ds_c + ds_b
          diff += addend
          _UpperCAmelCase     							=   0
          for j in range(__lowercase       ):
               _UpperCAmelCase     							=   a_i[j] + addend
               _UpperCAmelCase							,  _UpperCAmelCase     							=   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 	UpperCAmelCase_							(					__lowercase							:      List[str]			,     __lowercase							:      Tuple			,     __lowercase							:      int       )		->       str:


     '''simple docstring'''



     for j in range(__lowercase			,     len(__lowercase       )       ):
          _UpperCAmelCase     							=   digits[j] + addend
          if s >= 10:
               _UpperCAmelCase							,  _UpperCAmelCase     							=   divmod(__lowercase			,     10       )
               _UpperCAmelCase     							=   addend // 10 + quotient
          else:
               _UpperCAmelCase     							=   s
               _UpperCAmelCase     							=   addend // 10

          if addend == 0:
               break

     while addend > 0:
          _UpperCAmelCase							,  _UpperCAmelCase     							=   divmod(__lowercase			,     10       )
          digits.append(__lowercase       )
def 	UpperCAmelCase_							(					__lowercase							:      int = 10**15       )		->       int:


     '''simple docstring'''



     _UpperCAmelCase     							=   [1]
     _UpperCAmelCase     							=   1
     _UpperCAmelCase     							=   0
     while True:
          _UpperCAmelCase							,  _UpperCAmelCase     							=   next_term(__lowercase			,     20			,     i + dn			,     __lowercase       )
          dn += terms_jumped
          if dn == n - i:
               break

     _UpperCAmelCase     							=   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 re

from filelock import FileLock


try:
  import nltk

  __SCREAMING_SNAKE_CASE     :Optional[int]       =				True
except (ImportError, ModuleNotFoundError):
  __SCREAMING_SNAKE_CASE     :str       =				False

if NLTK_AVAILABLE:
  with FileLock('''.lock''') as lock:
    nltk.download('''punkt''', quiet=True)
def 	UpperCAmelCase_							(					__lowercase							:      str       )		->       str:


     '''simple docstring'''



     re.sub("<n>"			,     ""			,     __lowercase       )  # remove pegasus newline char
     assert NLTK_AVAILABLE, "nltk must be installed to separate newlines between sentences. (pip install nltk)"
     return "\n".join(nltk.sent_tokenize(__lowercase       )       )




