


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


def     lowercase	(    a     , a     , a     , a ):



		'''simple docstring'''




		SCREAMING_SNAKE_CASE_				:Tuple				     =						sum(a_i[j] for j in range(UpperCAmelCase_     , len(UpperCAmelCase_ ) ) )
		SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						sum(a_i[j] * base[j] for j in range(min(len(UpperCAmelCase_ )     , UpperCAmelCase_ ) ) )

		SCREAMING_SNAKE_CASE_				:str				     =						0, 0
		SCREAMING_SNAKE_CASE_				:Optional[int]				     =						n - i

		SCREAMING_SNAKE_CASE_				:List[Any]				     =						memo.get(UpperCAmelCase_ )

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

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

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

				else:
						SCREAMING_SNAKE_CASE_				:List[str]				     =						[]
		else:
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						{c: []}
				SCREAMING_SNAKE_CASE_				: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
						SCREAMING_SNAKE_CASE_				:int				     =						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
				SCREAMING_SNAKE_CASE_				:int				     =						compute(UpperCAmelCase_     , UpperCAmelCase_     , i + dn     , UpperCAmelCase_ )
				diff += _diff
				dn += terms_jumped

		SCREAMING_SNAKE_CASE_				:List[Any]				     =						sub_memo[c]

		# keep jumps sorted by # of terms skipped
		SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						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     lowercase	(    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)
		SCREAMING_SNAKE_CASE_				:List[str]				     =						i
		SCREAMING_SNAKE_CASE_				: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
				SCREAMING_SNAKE_CASE_				:Dict				     =						ds_c + ds_b
				diff += addend
				SCREAMING_SNAKE_CASE_				:List[Any]				     =						0
				for j in range(UpperCAmelCase_ ):
						SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						a_i[j] + addend
						SCREAMING_SNAKE_CASE_				: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     lowercase	(    a     , a     , a ):



		'''simple docstring'''




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

				if addend == 0:
						break

		while addend > 0:
				SCREAMING_SNAKE_CASE_				:Optional[Any]				     =						divmod(UpperCAmelCase_     , 10 )
				digits.append(UpperCAmelCase_ )


def     lowercase	(    a = 10**15 ):



		'''simple docstring'''




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

		SCREAMING_SNAKE_CASE_				:List[Any]				     =						0
		for j in range(len(UpperCAmelCase_ ) ):
				a_n += digits[j] * 10**j
		return a_n


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











'''simple docstring'''
def A__       (	UpperCAmelCase_ = 1_0_0_0				):
						_UpperCamelCase   :						List[str]												=  3
						_UpperCamelCase   :						Any												=  0
						while a < n:
												if a % 3 == 0 or a % 5 == 0:
																		result += a
												elif a % 1_5 == 0:
																		result -= a
												a += 1
						return result


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


