

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


def 					_UpperCAmelCase				(						a__  ,	a__  ,	a__  ,	a__):

			'''simple docstring'''



			a_						:						Tuple 							= sum(a_i[j] for j in range(a__  ,	len(a__)))
			a_						:						int 							= sum(a_i[j] * base[j] for j in range(min(len(a__)  ,	a__)))

			a_							,					a_						:						Tuple 							= 0, 0
			a_						:						List[str] 							= n - i

			a_						:						Tuple 							= memo.get(a__)

			if sub_memo is not None:
						a_						:						Optional[Any] 							= sub_memo.get(a__)

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

									if max_jump >= 0:
												a_							,					a_							,					a_						:						Tuple 							= jumps[max_jump]
												# since the difference between jumps is cached, add c
												a_						:						Union[str, Any] 							= diff + c
												for j in range(min(a__  ,	len(a__))):
															a_							,					a_						:						Dict 							= divmod(a__  ,	1_0)
												if new_c > 0:
															add(a__  ,	a__  ,	a__)

						else:
									a_						:						int 							= []
			else:
						a_						:						Dict 							= {c: []}
						a_						:						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(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_						:						Optional[int] 							= compute(a__  ,	a__  ,	i + dn  ,	a__)
						diff += _diff
						dn += terms_jumped

			a_						:						List[Any] 							= sub_memo[c]

			# keep jumps sorted by # of terms skipped
			a_						:						str 							= 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 					_UpperCAmelCase				(						a__  ,	a__  ,	a__  ,	a__):

			'''simple docstring'''



			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_						:						Union[str, Any] 							= 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_						:						int 							= ds_c + ds_b
						diff += addend
						a_						:						Any 							= 0
						for j in range(a__):
									a_						:						Dict 							= a_i[j] + addend
									a_							,					a_						:						List[str] 							= divmod(a__  ,	1_0)

									ds_c += a_i[j]

						if addend > 0:
									break

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


def 					_UpperCAmelCase				(						a__  ,	a__  ,	a__):

			'''simple docstring'''



			for j in range(a__  ,	len(a__)):
						a_						:						Any 							= digits[j] + addend
						if s >= 1_0:
									a_							,					a_						:						Optional[int] 							= divmod(a__  ,	1_0)
									a_						:						Any 							= addend // 1_0 + quotient
						else:
									a_						:						Any 							= s
									a_						:						int 							= addend // 1_0

						if addend == 0:
									break

			while addend > 0:
						a_							,					a_						:						Optional[int] 							= divmod(a__  ,	1_0)
						digits.append(a__)


def 					_UpperCAmelCase				(						a__ = 1_0**1_5):

			'''simple docstring'''



			a_						:						Optional[Any] 							= [1]
			a_						:						Any 							= 1
			a_						:						int 							= 0
			while True:
						a_							,					a_						:						Dict 							= next_term(a__  ,	2_0  ,	i + dn  ,	a__)
						dn += terms_jumped
						if dn == n - i:
									break

			a_						:						str 							= 0
			for j in range(len(a__)):
						a_n += digits[j] * 1_0**j
			return a_n


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





def 					_UpperCAmelCase				(						a__  ,	a__):

			'''simple docstring'''



			return x if y == 0 else greatest_common_divisor(a__  ,	x % y)


def 					_UpperCAmelCase				(						a__  ,	a__):

			'''simple docstring'''



			return (x * y) // greatest_common_divisor(a__  ,	a__)


def 					_UpperCAmelCase				(						a__ = 2_0):

			'''simple docstring'''



			a_						:						Any 							= 1
			for i in range(1  ,	n + 1):
						a_						:						Tuple 							= lcm(a__  ,	a__)
			return g


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


