






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

def    UpperCamelCase						(	_A,   _A,   _A,   _A			):






						"""simple docstring"""







						__magic_name__      :       Optional[int]       						= sum(a_i[j] for j in range(UpperCAmelCase_,   len(UpperCAmelCase_			)			)			)
						__magic_name__      :       int       						= sum(a_i[j] * base[j] for j in range(min(len(UpperCAmelCase_			),   UpperCAmelCase_			)			)			)

						__magic_name__						,__magic_name__      :       List[Any]       						= 0, 0
						__magic_name__      :       int       						= n - i

						__magic_name__      :       Any       						= memo.get(UpperCAmelCase_			)

						if sub_memo is not None:
												__magic_name__      :       Any       						= sub_memo.get(UpperCAmelCase_			)

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

																		if max_jump >= 0:
																								__magic_name__						,__magic_name__						,__magic_name__      :       Any       						= jumps[max_jump]
																								# since the difference between jumps is cached, add c
																								__magic_name__      :       Union[str, Any]       						= diff + c
																								for j in range(min(UpperCAmelCase_,   len(UpperCAmelCase_			)			)			):
																														__magic_name__						,__magic_name__      :       Optional[int]       						= divmod(UpperCAmelCase_,   10			)
																								if new_c > 0:
																														add(UpperCAmelCase_,   UpperCAmelCase_,   UpperCAmelCase_			)

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

						__magic_name__      :       Optional[int]       						= sub_memo[c]

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

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

def    UpperCamelCase						(	_A,   _A,   _A,   _A			):






						"""simple docstring"""







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

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

						while i < n:
												i += 1
												__magic_name__      :       int       						= ds_c + ds_b
												diff += addend
												__magic_name__      :       List[Any]       						= 0
												for j in range(UpperCAmelCase_			):
																		__magic_name__      :       Optional[int]       						= a_i[j] + addend
																		__magic_name__						,__magic_name__      :       Optional[Any]       						= divmod(UpperCAmelCase_,   10			)

																		ds_c += a_i[j]

												if addend > 0:
																		break

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

def    UpperCamelCase						(	_A,   _A,   _A			):






						"""simple docstring"""







						for j in range(UpperCAmelCase_,   len(UpperCAmelCase_			)			):
												__magic_name__      :       Optional[Any]       						= digits[j] + addend
												if s >= 10:
																		__magic_name__						,__magic_name__      :       List[str]       						= divmod(UpperCAmelCase_,   10			)
																		__magic_name__      :       Union[str, Any]       						= addend // 10 + quotient
												else:
																		__magic_name__      :       Optional[Any]       						= s
																		__magic_name__      :       Dict       						= addend // 10

												if addend == 0:
																		break

						while addend > 0:
												__magic_name__						,__magic_name__      :       Dict       						= divmod(UpperCAmelCase_,   10			)
												digits.append(UpperCAmelCase_			)

def    UpperCamelCase						(	_A = 10**15			):






						"""simple docstring"""







						__magic_name__      :       Union[str, Any]       						= [1]
						__magic_name__      :       int       						= 1
						__magic_name__      :       Union[str, Any]       						= 0
						while True:
												__magic_name__						,__magic_name__      :       List[str]       						= next_term(UpperCAmelCase_,   20,   i + dn,   UpperCAmelCase_			)
												dn += terms_jumped
												if dn == n - i:
																		break

						__magic_name__      :       Tuple       						= 0
						for j in range(len(UpperCAmelCase_			)			):
												a_n += digits[j] * 10**j
						return a_n


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














def    UpperCamelCase						(	_A = 1,   _A = 1000			):






						"""simple docstring"""







						__magic_name__      :       Optional[int]       						= 1
						__magic_name__      :       Dict       						= 0

						for divide_by_number in range(_A,   digit + 1			):
												__magic_name__      :       list[int]       						= []
												__magic_name__      :       Any       						= numerator
												for _ in range(1,   digit + 1			):
																		if now_divide in has_been_divided:
																								if longest_list_length < len(_A			):
																														__magic_name__      :       int       						= len(_A			)
																														__magic_name__      :       Dict       						= divide_by_number
																		else:
																								has_been_divided.append(_A			)
																								__magic_name__      :       Optional[int]       						= now_divide * 10 % divide_by_number

						return the_digit


# Tests
if __name__ == "__main__":
		import doctest

		doctest.testmod()
