


__UpperCamelCase     		=							range(2, 2_0 + 1)
__UpperCamelCase     		=							[1_0**k for k in range(ks[-1] + 1)]
__UpperCamelCase     		=							{}
def 							UpperCamelCase_(					_A :Any					,  _A :str					,  _A :Optional[Any]					,  _A :Optional[Any]	)->		str:
			UpperCamelCase__       =							sum(a_i[j] for j in range(_A					,  len(_A	)	)	)
			UpperCamelCase__       =							sum(a_i[j] * base[j] for j in range(min(len(_A	)					,  _A	)	)	)

			UpperCamelCase__,   UpperCamelCase__       =							0, 0
			UpperCamelCase__       =							n - i

			UpperCamelCase__       =							memo.get(_A	)

			if sub_memo is not None:
						UpperCamelCase__       =							sub_memo.get(_A	)

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

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

						else:
									UpperCamelCase__       =							[]
			else:
						UpperCamelCase__       =							{c: []}
						UpperCamelCase__       =							sub_memo

			if dn >= max_dn or c + diff >= base[k]:
						return diff, dn

			if k > ks[0]:
						while True:
									# keep doing smaller jumps
									UpperCamelCase__,   UpperCamelCase__       =							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
						UpperCamelCase__,   UpperCamelCase__       =							compute(_A					,  _A					,  i + dn					,  _A	)
						diff += _diff
						dn += terms_jumped

			UpperCamelCase__       =							sub_memo[c]

			# keep jumps sorted by # of terms skipped
			UpperCamelCase__       =							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 :Any					,  _A :int					,  _A :str					,  _A :Optional[Any]	)->		int:
			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)
			UpperCamelCase__       =							i
			UpperCamelCase__,   UpperCamelCase__,   UpperCamelCase__       =							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
						UpperCamelCase__       =							ds_c + ds_b
						diff += addend
						UpperCamelCase__       =							0
						for j in range(_A	):
									UpperCamelCase__       =							a_i[j] + addend
									UpperCamelCase__,   UpperCamelCase__       =							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 							UpperCamelCase_(					_A :List[str]					,  _A :Optional[Any]					,  _A :Any	)->		Dict:
			for j in range(_A					,  len(_A	)	):
						UpperCamelCase__       =							digits[j] + addend
						if s >= 10:
									UpperCamelCase__,   UpperCamelCase__       =							divmod(_A					,  10	)
									UpperCamelCase__       =							addend // 10 + quotient
						else:
									UpperCamelCase__       =							s
									UpperCamelCase__       =							addend // 10

						if addend == 0:
									break

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

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


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






from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
						if not (is_transformers_available() and is_torch_available()):
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ...utils.dummy_torch_and_transformers_objects import KandinskyPipeline, KandinskyPriorPipeline
else:
						from .pipeline_kandinsky import KandinskyPipeline
						from .pipeline_kandinsky_imgaimg import KandinskyImgaImgPipeline
						from .pipeline_kandinsky_inpaint import KandinskyInpaintPipeline
						from .pipeline_kandinsky_prior import KandinskyPriorPipeline, KandinskyPriorPipelineOutput
						from .text_encoder import MultilingualCLIP


