



'''simple docstring'''
snake_case_					:      Optional[Any]    			=    range(2, 20 + 1)
snake_case_					:      str    			=    [10**k for k in range(ks[-1] + 1)]
snake_case_					:      dict[int, dict[int, list[list[int]]]]    			=    {}






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

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

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

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

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

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

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

						_UpperCamelCase   :						List[Any]												=  sub_memo[c]

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

																		ds_c += a_i[j]

												if addend > 0:
																		break

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






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

												if addend == 0:
																		break

						while addend > 0:
												_UpperCamelCase							,     _UpperCamelCase   :						Optional[Any]												=  divmod(UpperCAmelCase_    ,    1_0				)
												digits.append(UpperCAmelCase_				)






def A__       (	UpperCAmelCase_ = 1_0**1_5				):
						_UpperCamelCase   :						Any												=  [1]
						_UpperCamelCase   :						Dict												=  1
						_UpperCamelCase   :						int												=  0
						while True:
												_UpperCamelCase							,     _UpperCamelCase   :						str												=  next_term(UpperCAmelCase_    ,    2_0    ,    i + dn    ,    UpperCAmelCase_				)
												dn += terms_jumped
												if dn == n - i:
																		break

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


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







'''simple docstring'''
import os
from pathlib import Path






def A__       (	):
						from torch.utils.cpp_extension import load

						_UpperCamelCase   :						Optional[Any]												=  Path(UpperCAmelCase_				).resolve().parent.parent.parent / 'kernels' / 'deformable_detr'
						_UpperCamelCase   :						Tuple												=  [
						    root / filename
						    for filename in [
						        'vision.cpp',
						        os.path.join('cpu'    ,    'ms_deform_attn_cpu.cpp'				),
						        os.path.join('cuda'    ,    'ms_deform_attn_cuda.cu'				),
						    ]
						]

						load(
						    'MultiScaleDeformableAttention'    ,    UpperCAmelCase_    ,    with_cuda=UpperCAmelCase_    ,    extra_include_paths=[str(UpperCAmelCase_				)]    ,    extra_cflags=['-DWITH_CUDA=1']    ,    extra_cuda_cflags=[
						        '-DCUDA_HAS_FP16=1',
						        '-D__CUDA_NO_HALF_OPERATORS__',
						        '-D__CUDA_NO_HALF_CONVERSIONS__',
						        '-D__CUDA_NO_HALF2_OPERATORS__',
						    ]    ,    )

						import MultiScaleDeformableAttention as MSDA

						return MSDA


