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


def 				__A(lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase			)		->					List[str]:

		"""simple docstring"""






		_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         =						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         =						jumps[max_jump]
								# since the difference between jumps is cached, add c
								_UpperCamelCase         =						diff + c
								for j in range(min(a_    ,	len(a_			)			)			):
										_UpperCamelCase         =						divmod(a_    ,	1_0			)
								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         =						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         =						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 				__A(lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase			)		->					Optional[Any]:

		"""simple docstring"""






		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         =						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         =						divmod(a_    ,	1_0			)

						ds_c += a_i[j]

				if addend > 0:
						break

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


def 				__A(lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase			)		->					List[str]:

		"""simple docstring"""






		for j in range(a_    ,	len(a_			)			):
				_UpperCamelCase         =						digits[j] + addend
				if s >= 1_0:
						_UpperCamelCase         =						divmod(a_    ,	1_0			)
						_UpperCamelCase         =						addend // 1_0 + quotient
				else:
						_UpperCamelCase         =						s
						_UpperCamelCase         =						addend // 1_0

				if addend == 0:
						break

		while addend > 0:
				_UpperCamelCase         =						divmod(a_    ,	1_0			)
				digits.append(a_			)


def 				__A(lowerCAmelCase = 1_0**1_5			)		->					int:

		"""simple docstring"""






		_UpperCamelCase         =						[1]
		_UpperCamelCase         =						1
		_UpperCamelCase         =						0
		while True:
				_UpperCamelCase         =						next_term(a_    ,	2_0    ,	i + dn    ,	a_			)
				dn += terms_jumped
				if dn == n - i:
						break

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


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










'''simple docstring'''






import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType
class 		lowerCamelCase	(   _A							):
	snake_case_   = ["image_processor", "tokenizer"]
	snake_case_   = "LayoutLMv3ImageProcessor"
	snake_case_   = ("LayoutLMv3Tokenizer", "LayoutLMv3TokenizerFast")



	def __init__( self		,   a_=None		,   a_=None		,   **a_						):
			lowerCAmelCase  :     Union[str, Any]       						= None
			if "feature_extractor" in kwargs:
					warnings.warn(
					    "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
					    " instead."		,   a_		,   )
					lowerCAmelCase  :     Tuple       						= kwargs.pop("feature_extractor"						)

			lowerCAmelCase  :     str       						= image_processor if image_processor is not None else feature_extractor
			if image_processor is None:
					raise ValueError("You need to specify an `image_processor`."						)
			if tokenizer is None:
					raise ValueError("You need to specify a `tokenizer`."						)

			super().__init__(a_		,   a_						)



	def __call__( self		,   a_		,   a_ = None		,   a_ = None		,   a_ = None		,   a_ = None		,   a_ = True		,   a_ = False		,   a_ = None		,   a_ = None		,   a_ = 0		,   a_ = None		,   a_ = None		,   a_ = None		,   a_ = False		,   a_ = False		,   a_ = False		,   a_ = False		,   a_ = True		,   a_ = None		,   **a_		,   ):
			# verify input
			if self.image_processor.apply_ocr and (boxes is not None):
					raise ValueError(
					    "You cannot provide bounding boxes if you initialized the image processor with apply_ocr set to True."						)

			if self.image_processor.apply_ocr and (word_labels is not None):
					raise ValueError(
					    "You cannot provide word labels if you initialized the image processor with apply_ocr set to True."						)

			# first, apply the image processor
			lowerCAmelCase  :     str       						= self.image_processor(images=a_		,   return_tensors=a_						)

			# second, apply the tokenizer
			if text is not None and self.image_processor.apply_ocr and text_pair is None:
					if isinstance(a_		,   a_						):
							lowerCAmelCase  :     Union[str, Any]       						= [text]  # add batch dimension (as the image processor always adds a batch dimension)
					lowerCAmelCase  :     int       						= features["words"]

			lowerCAmelCase  :     List[Any]       						= self.tokenizer(
			    text=text if text is not None else features["words"]		,   text_pair=text_pair if text_pair is not None else None		,   boxes=boxes if boxes is not None else features["boxes"]		,   word_labels=a_		,   add_special_tokens=a_		,   padding=a_		,   truncation=a_		,   max_length=a_		,   stride=a_		,   pad_to_multiple_of=a_		,   return_token_type_ids=a_		,   return_attention_mask=a_		,   return_overflowing_tokens=a_		,   return_special_tokens_mask=a_		,   return_offsets_mapping=a_		,   return_length=a_		,   verbose=a_		,   return_tensors=a_		,   **a_		,   )

			# add pixel values
			lowerCAmelCase  :     Tuple       						= features.pop("pixel_values"						)
			if return_overflowing_tokens is True:
					lowerCAmelCase  :     Optional[int]       						= self.get_overflowing_images(a_		,   encoded_inputs["overflow_to_sample_mapping"]						)
			lowerCAmelCase  :     str       						= images

			return encoded_inputs



	def 	_lowerCamelCase     ( self		,   a_		,   a_						):
			# in case there's an overflow, ensure each `input_ids` sample is mapped to its corresponding image
			lowerCAmelCase  :     Optional[Any]       						= []
			for sample_idx in overflow_to_sample_mapping:
					images_with_overflow.append(images[sample_idx]						)

			if len(a_						) != len(a_						):
					raise ValueError(
					    "Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got"
					    F''' {len(a_						)} and {len(a_						)}'''						)

			return images_with_overflow



	def 	_lowerCamelCase     ( self		,   *a_		,   **a_						):
			return self.tokenizer.batch_decode(*a_		,   **a_						)



	def 	_lowerCamelCase     ( self		,   *a_		,   **a_						):
			return self.tokenizer.decode(*a_		,   **a_						)



	@property
	def 	_lowerCamelCase     ( self						):
			return ["input_ids", "bbox", "attention_mask", "pixel_values"]



	@property
	def 	_lowerCamelCase     ( self						):
			warnings.warn(
			    "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."		,   a_		,   )
			return self.image_processor_class





	@property
	def 	_lowerCamelCase     ( self						):
			warnings.warn(
			    "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."		,   a_		,   )
			return self.image_processor



