





from __future__ import annotations

from collections.abc import Callable
from typing import Any, Generic, TypeVar

lowerCAmelCase_        =							TypeVar('''T''')



class    __lowerCAmelCase			(     Generic[T]	):






			def __init__(self   ,				__magic_name__   ,				__magic_name__       )	->  None:


							'''simple docstring'''



							snake_case_		:       Any | T           =    None

							snake_case_		:       int           =    len(__magic_name__       )
							snake_case_		:       list[T]           =    [any_type for _ in range(self.N       )] + arr
							snake_case_		:       Optional[int]           =    fnc
							self.build()






			def      lowerCamelCase    (self       )	->  None:


							'''simple docstring'''



							for p in range(self.N - 1   ,				0   ,				-1       ):
											snake_case_		:       Optional[Any]           =    self.fn(self.st[p * 2]   ,				self.st[p * 2 + 1]       )






			def      lowerCamelCase    (self   ,				__magic_name__   ,				__magic_name__       )	->  None:


							'''simple docstring'''



							p += self.N
							snake_case_		:       Dict           =    v
							while p > 1:
											snake_case_		:       List[str]           =    p // 2
											snake_case_		:       int           =    self.fn(self.st[p * 2]   ,				self.st[p * 2 + 1]       )






			def      lowerCamelCase    (self   ,				__magic_name__   ,				__magic_name__       )	->  T | None:  # noqa: E741


							'''simple docstring'''



							snake_case_     ,				snake_case_		:       int           =    l + self.N, r + self.N

							snake_case_		:       T | None           =    None
							while l <= r:
											if l % 2 == 1:
															snake_case_		:       Optional[Any]           =    self.st[l] if res is None else self.fn(__magic_name__   ,				self.st[l]       )
											if r % 2 == 0:
															snake_case_		:       Optional[int]           =    self.st[r] if res is None else self.fn(__magic_name__   ,				self.st[r]       )
											snake_case_     ,				snake_case_		:       Dict           =    (l + 1) // 2, (r - 1) // 2
							return res


if __name__ == "__main__":
	from functools import reduce

	lowerCAmelCase_        =							[1, 1_0, -2, 9, -3, 8, 4, -7, 5, 6, 1_1, -1_2]

	lowerCAmelCase_        =							{
	    0: 7,
	    1: 2,
	    2: 6,
	    3: -1_4,
	    4: 5,
	    5: 4,
	    6: 7,
	    7: -1_0,
	    8: 9,
	    9: 1_0,
	    1_0: 1_2,
	    1_1: 1,
	}

	lowerCAmelCase_        =							SegmentTree(test_array, min)
	lowerCAmelCase_        =							SegmentTree(test_array, max)
	lowerCAmelCase_        =							SegmentTree(test_array, lambda a, b: a + b)






	def 	lowerCamelCase_		(							)						->		None:






					"""simple docstring"""


					for i in range(len(_UpperCamelCase					)					):
									for j in range(_UpperCamelCase					,							len(_UpperCamelCase					)					):
													snake_case_		:       Dict           =    reduce(_UpperCamelCase					,							test_array[i : j + 1]					)
													snake_case_		:       Tuple           =    reduce(_UpperCamelCase					,							test_array[i : j + 1]					)
													snake_case_		:       Tuple           =    reduce(lambda _UpperCamelCase					,							_UpperCamelCase					: a + b					,							test_array[i : j + 1]					)
													assert min_range == min_segment_tree.query(_UpperCamelCase					,							_UpperCamelCase					)
													assert max_range == max_segment_tree.query(_UpperCamelCase					,							_UpperCamelCase					)
													assert sum_range == sum_segment_tree.query(_UpperCamelCase					,							_UpperCamelCase					)

	test_all_segments()

	for index, value in test_updates.items():
		lowerCAmelCase_        =							value
		min_segment_tree.update(index, value)
		max_segment_tree.update(index, value)
		sum_segment_tree.update(index, value)
		test_all_segments()






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




def 		lowerCAmelCase_ (						lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase ):
				__magic_name__						:						Union[str, Any]										=sum(a_i[j] for j in range(lowerCamelCase						,  len(lowerCamelCase ) ) )
				__magic_name__						:						Any										=sum(a_i[j] * base[j] for j in range(min(len(lowerCamelCase )						,  lowerCamelCase ) ) )

				__magic_name__					,			__magic_name__						:						Tuple										=0, 0
				__magic_name__						:						Optional[Any]										=n - i

				__magic_name__						:						Union[str, Any]										=memo.get(lowerCamelCase )

				if sub_memo is not None:
								__magic_name__						:						int										=sub_memo.get(lowerCamelCase )

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

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

								else:
												__magic_name__						:						str										=[]
				else:
								__magic_name__						:						List[str]										={c: []}
								__magic_name__						:						List[str]										=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(lowerCamelCase						,  k - 1						,  i + dn						,  lowerCamelCase )
												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__						:						Optional[int]										=compute(lowerCamelCase						,  lowerCamelCase						,  i + dn						,  lowerCamelCase )
								diff += _diff
								dn += terms_jumped

				__magic_name__						:						Tuple										=sub_memo[c]

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

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




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

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

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

												ds_c += a_i[j]

								if addend > 0:
												break

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




def 		lowerCAmelCase_ (						lowerCamelCase						,  lowerCamelCase						,  lowerCamelCase ):
				for j in range(lowerCamelCase						,  len(lowerCamelCase ) ):
								__magic_name__						:						Tuple										=digits[j] + addend
								if s >= 10:
												__magic_name__					,			__magic_name__						:						int										=divmod(lowerCamelCase						,  10 )
												__magic_name__						:						int										=addend // 10 + quotient
								else:
												__magic_name__						:						Dict										=s
												__magic_name__						:						Any										=addend // 10

								if addend == 0:
												break

				while addend > 0:
								__magic_name__					,			__magic_name__						:						Union[str, Any]										=divmod(lowerCamelCase						,  10 )
								digits.append(lowerCamelCase )




def 		lowerCAmelCase_ (						lowerCamelCase = 10**15 ):
				__magic_name__						:						List[str]										=[1]
				__magic_name__						:						str										=1
				__magic_name__						:						str										=0
				while True:
								__magic_name__					,			__magic_name__						:						List[str]										=next_term(lowerCamelCase						,  20						,  i + dn						,  lowerCamelCase )
								dn += terms_jumped
								if dn == n - i:
												break

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


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




