






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







def 		SCREAMING_SNAKE_CASE							( __lowerCAmelCase ,   __lowerCAmelCase ,   __lowerCAmelCase ,   __lowerCAmelCase      )			->     Dict:
     UpperCamelCase__      :       List[Any]	    =  sum(a_i[j] for j in range(__lowerCAmelCase ,   len(__lowerCAmelCase      )      )      )
     UpperCamelCase__      :       Dict	    =  sum(a_i[j] * base[j] for j in range(min(len(__lowerCAmelCase      ) ,   __lowerCAmelCase      )      )      )

     UpperCamelCase__    ,					UpperCamelCase__      :       Any	    =  0, 0
     UpperCamelCase__      :       Union[str, Any]	    =  n - i

     UpperCamelCase__      :       Optional[int]	    =  memo.get(__lowerCAmelCase      )

     if sub_memo is not None:
          UpperCamelCase__      :       str	    =  sub_memo.get(__lowerCAmelCase      )

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

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

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

     UpperCamelCase__      :       Optional[int]	    =  sub_memo[c]

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

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







def 		SCREAMING_SNAKE_CASE							( __lowerCAmelCase ,   __lowerCAmelCase ,   __lowerCAmelCase ,   __lowerCAmelCase      )			->     Optional[int]:
     if i >= n:
          return 0, i
     if k > len(__lowerCAmelCase      ):
          a_i.extend([0 for _ in range(k - len(__lowerCAmelCase      )      )]      )

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

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

               ds_c += a_i[j]

          if addend > 0:
               break

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







def 		SCREAMING_SNAKE_CASE							( __lowerCAmelCase ,   __lowerCAmelCase ,   __lowerCAmelCase      )			->     List[str]:
     for j in range(__lowerCAmelCase ,   len(__lowerCAmelCase      )      ):
          UpperCamelCase__      :       Optional[Any]	    =  digits[j] + addend
          if s >= 10:
               UpperCamelCase__    ,					UpperCamelCase__      :       str	    =  divmod(__lowerCAmelCase ,   10      )
               UpperCamelCase__      :       str	    =  addend // 10 + quotient
          else:
               UpperCamelCase__      :       List[Any]	    =  s
               UpperCamelCase__      :       Optional[Any]	    =  addend // 10

          if addend == 0:
               break

     while addend > 0:
          UpperCamelCase__    ,					UpperCamelCase__      :       Tuple	    =  divmod(__lowerCAmelCase ,   10      )
          digits.append(__lowerCAmelCase      )







def 		SCREAMING_SNAKE_CASE							( __lowerCAmelCase = 10**15      )			->     int:
     UpperCamelCase__      :       List[Any]	    =  [1]
     UpperCamelCase__      :       List[Any]	    =  1
     UpperCamelCase__      :       Dict	    =  0
     while True:
          UpperCamelCase__    ,					UpperCamelCase__      :       Optional[int]	    =  next_term(__lowerCAmelCase ,   20 ,   i + dn ,   __lowerCAmelCase      )
          dn += terms_jumped
          if dn == n - i:
               break

     UpperCamelCase__      :       int	    =  0
     for j in range(len(__lowerCAmelCase      )      ):
          a_n += digits[j] * 10**j
     return a_n


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







def 		SCREAMING_SNAKE_CASE							( __lowerCAmelCase      )			->     int:
     assert isinstance(__lowerCAmelCase ,   __lowerCAmelCase      ), f'The input value of [n={number}] is not an integer'

     if number == 1:
          return 2
     elif number < 1:
          UpperCamelCase__      :       List[Any]	    =  f'The input value of [n={number}] has to be > 0'
          raise ValueError(__lowerCAmelCase      )
     else:
          UpperCamelCase__      :       Optional[Any]	    =  sylvester(number - 1      )
          UpperCamelCase__      :       str	    =  num - 1
          UpperCamelCase__      :       int	    =  num
          return lower * upper + 1


if __name__ == "__main__":
 print(F"""The 8th number in Sylvester's sequence: {sylvester(8)}""")