





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




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	)       ->     Any:
  lowercase__			    =						sum(a_i[j] for j in range(_SCREAMING_SNAKE_CASE	,		len(_SCREAMING_SNAKE_CASE	)	)	)
  lowercase__			    =						sum(a_i[j] * base[j] for j in range(min(len(_SCREAMING_SNAKE_CASE	)	,		_SCREAMING_SNAKE_CASE	)	)	)

  lowercase__    ,					lowercase__			    =						0, 0
  lowercase__			    =						n - i

  lowercase__			    =						memo.get(_SCREAMING_SNAKE_CASE	)

  if sub_memo is not None:
    lowercase__			    =						sub_memo.get(_SCREAMING_SNAKE_CASE	)

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

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

    else:
      lowercase__			    =						[]
  else:
    lowercase__			    =						{c: []}
    lowercase__			    =						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__			    =						next_term(_SCREAMING_SNAKE_CASE	,		k - 1	,		i + dn	,		_SCREAMING_SNAKE_CASE	)
      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__			    =						compute(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		i + dn	,		_SCREAMING_SNAKE_CASE	)
    diff += _diff
    dn += terms_jumped

  lowercase__			    =						sub_memo[c]

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

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




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

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

  while i < n:
    i += 1
    lowercase__			    =						ds_c + ds_b
    diff += addend
    lowercase__			    =						0
    for j in range(_SCREAMING_SNAKE_CASE	):
      lowercase__			    =						a_i[j] + addend
      lowercase__    ,					lowercase__			    =						divmod(_SCREAMING_SNAKE_CASE	,		10	)

      ds_c += a_i[j]

    if addend > 0:
      break

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




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	)       ->     Union[str, Any]:
  for j in range(_SCREAMING_SNAKE_CASE	,		len(_SCREAMING_SNAKE_CASE	)	):
    lowercase__			    =						digits[j] + addend
    if s >= 10:
      lowercase__    ,					lowercase__			    =						divmod(_SCREAMING_SNAKE_CASE	,		10	)
      lowercase__			    =						addend // 10 + quotient
    else:
      lowercase__			    =						s
      lowercase__			    =						addend // 10

    if addend == 0:
      break

  while addend > 0:
    lowercase__    ,					lowercase__			    =						divmod(_SCREAMING_SNAKE_CASE	,		10	)
    digits.append(_SCREAMING_SNAKE_CASE	)




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE = 10**15	)       ->     int:
  lowercase__			    =						[1]
  lowercase__			    =						1
  lowercase__			    =						0
  while True:
    lowercase__    ,					lowercase__			    =						next_term(_SCREAMING_SNAKE_CASE	,		20	,		i + dn	,		_SCREAMING_SNAKE_CASE	)
    dn += terms_jumped
    if dn == n - i:
      break

  lowercase__			    =						0
  for j in range(len(_SCREAMING_SNAKE_CASE	)	):
    a_n += digits[j] * 10**j
  return a_n


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









class        SCREAMING_SNAKE_CASE     :  # Public class to implement a graph


   def __init__(					self    :       int    ,  a    :       int    ,  a    :       int    ,  a    :       list[list[bool]] )->     None:





     """simple docstring"""







     lowercase__			    =						row
     lowercase__			    =						col
     lowercase__			    =						graph


   def  SCREAMING_SNAKE_CASE_							(					self    :       Dict    ,  a    :       int    ,  a    :       int    ,  a    :       list[list[bool]] )->     bool:





     """simple docstring"""







     return (
         0 <= i < self.ROW
         and 0 <= j < self.COL
         and not visited[i][j]
         and self.graph[i][j]
     )


   def  SCREAMING_SNAKE_CASE_							(					self    :       List[str]    ,  a    :       int    ,  a    :       int    ,  a    :       list[list[bool]] )->     None:





     """simple docstring"""







     lowercase__			    =						[-1, -1, -1, 0, 0, 1, 1, 1]  # Coordinate order
     lowercase__			    =						[-1, 0, 1, -1, 1, -1, 0, 1]
     lowercase__			    =						True  # Make those cells visited
     for k in range(8 ):
       if self.is_safe(i + row_nbr[k]    ,  j + col_nbr[k]    ,  a ):
         self.diffs(i + row_nbr[k]    ,  j + col_nbr[k]    ,  a )


   def  SCREAMING_SNAKE_CASE_							(					self    :       List[str] )->     int:  # And finally, count all islands.





     """simple docstring"""







     lowercase__			    =						[[False for j in range(self.COL )] for i in range(self.ROW )]
     lowercase__			    =						0
     for i in range(self.ROW ):
       for j in range(self.COL ):
         if visited[i][j] is False and self.graph[i][j] == 1:
           self.diffs(a    ,  a    ,  a )
           count += 1
     return count


