



'''simple docstring'''






lowerCAmelCase: Optional[int]							=						range(2, 2_0 + 1)
lowerCAmelCase: str							=						[1_0**k for k in range(ks[-1] + 1)]
lowerCAmelCase: dict[int, dict[int, list[list[int]]]]							=						{}
def 				lowerCamelCase__	(						_A			,      _A			,      _A			,      _A    ):
  a						: Optional[Any]					       =					sum(a_i[j] for j in range(_A			,      len(_A    )    )    )
  a						: Any					       =					sum(a_i[j] * base[j] for j in range(min(len(_A    )			,      _A    )    )    )

  a       ,     a						: Optional[int]					       =					0, 0
  a						: Dict					       =					n - i

  a						: List[Any]					       =					memo.get(_A    )

  if sub_memo is not None:
    a						: List[Any]					       =					sub_memo.get(_A    )

    if jumps is not None and len(_A    ) > 0:
      # find and make the largest jump without going over
      a						: Optional[int]					       =					-1
      for _k in range(len(_A    ) - 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						: str					       =					jumps[max_jump]
        # since the difference between jumps is cached, add c
        a						: Optional[Any]					       =					diff + c
        for j in range(min(_A			,      len(_A    )    )    ):
          a       ,     a						: str					       =					divmod(_A			,      10    )
        if new_c > 0:
          add(_A			,      _A			,      _A    )

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

  a						: Union[str, Any]					       =					sub_memo[c]

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

  # cache the jump for this value digitsum(b) and c
  sub_memo[c].insert(_A			,      (diff, dn, k)    )
  return (diff, dn)
def 				lowerCamelCase__	(						_A			,      _A			,      _A			,      _A    ):
  if i >= n:
    return 0, i
  if k > len(_A    ):
    a_i.extend([0 for _ in range(k - len(_A    )    )]    )

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

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

      ds_c += a_i[j]

    if addend > 0:
      break

  if addend > 0:
    add(_A			,      _A			,      _A    )
  return diff, i - start_i
def 				lowerCamelCase__	(						_A			,      _A			,      _A    ):
  for j in range(_A			,      len(_A    )    ):
    a						: Union[str, Any]					       =					digits[j] + addend
    if s >= 10:
      a       ,     a						: str					       =					divmod(_A			,      10    )
      a						: str					       =					addend // 10 + quotient
    else:
      a						: Union[str, Any]					       =					s
      a						: Optional[int]					       =					addend // 10

    if addend == 0:
      break

  while addend > 0:
    a       ,     a						: int					       =					divmod(_A			,      10    )
    digits.append(_A    )
def 				lowerCamelCase__	(						_A = 10**15    ):
  a						: Optional[Any]					       =					[1]
  a						: Any					       =					1
  a						: Dict					       =					0
  while True:
    a       ,     a						: int					       =					next_term(_A			,      20			,      i + dn			,      _A    )
    dn += terms_jumped
    if dn == n - i:
      break

  a						: Dict					       =					0
  for j in range(len(_A    )    ):
    a_n += digits[j] * 10**j
  return a_n


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




'''simple docstring'''






import math

class 							a__:







    def __init__(				self			:  int						,      __snake_case			:  Any=0     ):  # a graph with Node 0,1,...,N-1
      a						: List[Any]					       =					n
      a						: Optional[Any]					       =					[
          [math.inf for j in range(0						,      __snake_case     )] for i in range(0						,      __snake_case     )
      ]  # adjacency matrix for weight
      a						: Dict					       =					[
          [math.inf for j in range(0						,      __snake_case     )] for i in range(0						,      __snake_case     )
      ]  # dp[i][j] stores minimum distance from i to j







    def       lowercase_	(				self			:  int						,      __snake_case			:  str						,      __snake_case			:  Tuple						,      __snake_case			:  int     ):
      a						: str					       =					w







    def       lowercase_	(				self			:  int     ):
      for k in range(0						,      self.n     ):
        for i in range(0						,      self.n     ):
          for j in range(0						,      self.n     ):
            a						: str					       =					min(self.dp[i][j]						,      self.dp[i][k] + self.dp[k][j]     )







    def       lowercase_	(				self			:  List[str]						,      __snake_case			:  Any						,      __snake_case			:  List[str]     ):
      return self.dp[u][v]


if __name__ == "__main__":
     lowerCAmelCase: Any							=						Graph(5)
     graph.add_edge(0, 2, 9)
     graph.add_edge(0, 4, 1_0)
     graph.add_edge(1, 3, 5)
     graph.add_edge(2, 3, 7)
     graph.add_edge(3, 0, 1_0)
     graph.add_edge(3, 1, 2)
     graph.add_edge(3, 2, 1)
     graph.add_edge(3, 4, 6)
     graph.add_edge(4, 1, 3)
     graph.add_edge(4, 2, 4)
     graph.add_edge(4, 3, 9)
     graph.floyd_warshall()
     graph.show_min(1, 4)
     graph.show_min(0, 3)