

import inspect
import tempfile
from collections import OrderedDict, UserDict
from collections.abc import MutableMapping
from contextlib import ExitStack, contextmanager
from dataclasses import fields
from enum import Enum
from typing import Any, ContextManager, List, Tuple

import numpy as np

from .import_utils import is_flax_available, is_tf_available, is_torch_available, is_torch_fx_proxy


if is_flax_available():
							import jax.numpy as jnp







class 	lowercase    (				_lowercase							):


		"""simple docstring"""




		def __get__(				self	,       __snake_case	,       __snake_case=None):
			# See docs.python.org/3/howto/descriptor.html#properties
			if obj is None:
				return self
			if self.fget is None:
				raise AttributeError('unreadable attribute')
			_UpperCamelCase   :		List[Any]			=						'__cached_' + self.fget.__name__
			_UpperCamelCase   :		List[str]			=						getattr(__snake_case	,       __snake_case	,       __snake_case)
			if cached is None:
				_UpperCamelCase   :		str			=						self.fget(__snake_case)
				setattr(__snake_case	,       __snake_case	,       __snake_case)
			return cached






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Any	)						->				str:




	'''simple docstring'''




	_UpperCamelCase   :		int			=						val.lower()
	if val in {"y", "yes", "t", "true", "on", "1"}:
		return 1
	if val in {"n", "no", "f", "false", "off", "0"}:
		return 0
	raise ValueError(F'''invalid truth value {val!r}'''	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     List[str]	)						->				Optional[Any]:




	'''simple docstring'''




	if is_torch_fx_proxy(UpperCAmelCase_	):
		return True
	if is_torch_available():
		import torch

		if isinstance(UpperCAmelCase_							,       torch.Tensor	):
			return True
	if is_tf_available():
		import tensorflow as tf

		if isinstance(UpperCAmelCase_							,       tf.Tensor	):
			return True

	if is_flax_available():
		import jax.numpy as jnp
		from jax.core import Tracer

		if isinstance(UpperCAmelCase_							,       (jnp.ndarray, Tracer)	):
			return True

	return isinstance(UpperCAmelCase_							,       np.ndarray	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Any	)						->				Any:




	'''simple docstring'''




	return isinstance(UpperCAmelCase_							,       np.ndarray	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Union[str, Any]	)						->				str:




	'''simple docstring'''




	return _is_numpy(UpperCAmelCase_	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     int	)						->				Optional[int]:




	'''simple docstring'''




	import torch

	return isinstance(UpperCAmelCase_							,       torch.Tensor	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Tuple	)						->				Any:




	'''simple docstring'''




	return False if not is_torch_available() else _is_torch(UpperCAmelCase_	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Tuple	)						->				str:




	'''simple docstring'''




	import torch

	return isinstance(UpperCAmelCase_							,       torch.device	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Dict	)						->				int:




	'''simple docstring'''




	return False if not is_torch_available() else _is_torch_device(UpperCAmelCase_	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Tuple	)						->				Tuple:




	'''simple docstring'''




	import torch

	if isinstance(UpperCAmelCase_							,       UpperCAmelCase_	):
		if hasattr(UpperCAmelCase_							,       UpperCAmelCase_	):
			_UpperCamelCase   :		Any			=						getattr(UpperCAmelCase_							,       UpperCAmelCase_	)
		else:
			return False
	return isinstance(UpperCAmelCase_							,       torch.dtype	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Dict	)						->				str:




	'''simple docstring'''




	return False if not is_torch_available() else _is_torch_dtype(UpperCAmelCase_	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Optional[int]	)						->				List[Any]:




	'''simple docstring'''




	import tensorflow as tf

	return isinstance(UpperCAmelCase_							,       tf.Tensor	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     int	)						->				Optional[int]:




	'''simple docstring'''




	return False if not is_tf_available() else _is_tensorflow(UpperCAmelCase_	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     str	)						->				Tuple:




	'''simple docstring'''




	import tensorflow as tf

	# the `is_symbolic_tensor` predicate is only available starting with TF 2.14
	if hasattr(UpperCAmelCase_							,       'is_symbolic_tensor'	):
		return tf.is_symbolic_tensor(UpperCAmelCase_	)
	return type(UpperCAmelCase_	) == tf.Tensor






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Any	)						->				List[str]:




	'''simple docstring'''




	return False if not is_tf_available() else _is_tf_symbolic_tensor(UpperCAmelCase_	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     str	)						->				Union[str, Any]:




	'''simple docstring'''




	import jax.numpy as jnp  # noqa: F811

	return isinstance(UpperCAmelCase_							,       jnp.ndarray	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Union[str, Any]	)						->				Optional[Any]:




	'''simple docstring'''




	return False if not is_flax_available() else _is_jax(UpperCAmelCase_	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     str	)						->				List[Any]:




	'''simple docstring'''




	if isinstance(UpperCAmelCase_							,       (dict, UserDict)	):
		return {k: to_py_obj(UpperCAmelCase_	) for k, v in obj.items()}
	elif isinstance(UpperCAmelCase_							,       (list, tuple)	):
		return [to_py_obj(UpperCAmelCase_	) for o in obj]
	elif is_tf_tensor(UpperCAmelCase_	):
		return obj.numpy().tolist()
	elif is_torch_tensor(UpperCAmelCase_	):
		return obj.detach().cpu().tolist()
	elif is_jax_tensor(UpperCAmelCase_	):
		return np.asarray(UpperCAmelCase_	).tolist()
	elif isinstance(UpperCAmelCase_							,       (np.ndarray, np.number)	):  # tolist also works on 0d np arrays
		return obj.tolist()
	else:
		return obj






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Tuple	)						->				Any:




	'''simple docstring'''




	if isinstance(UpperCAmelCase_							,       (dict, UserDict)	):
		return {k: to_numpy(UpperCAmelCase_	) for k, v in obj.items()}
	elif isinstance(UpperCAmelCase_							,       (list, tuple)	):
		return np.array(UpperCAmelCase_	)
	elif is_tf_tensor(UpperCAmelCase_	):
		return obj.numpy()
	elif is_torch_tensor(UpperCAmelCase_	):
		return obj.detach().cpu().numpy()
	elif is_jax_tensor(UpperCAmelCase_	):
		return np.asarray(UpperCAmelCase_	)
	else:
		return obj







class 	lowercase    (				_lowercase							):


		"""simple docstring"""




		def 		A__					(				self):
			_UpperCamelCase   :		Optional[int]			=						fields(self)

			# Safety and consistency checks
			if not len(__snake_case):
				raise ValueError(f'''{self.__class__.__name__} has no fields.''')
			if not all(field.default is None for field in class_fields[1:]):
				raise ValueError(f'''{self.__class__.__name__} should not have more than one required field.''')

			_UpperCamelCase   :		List[str]			=						getattr(self	,       class_fields[0].name)
			_UpperCamelCase   :		List[str]			=						all(getattr(self	,       field.name) is None for field in class_fields[1:])

			if other_fields_are_none and not is_tensor(__snake_case):
				if isinstance(__snake_case	,       __snake_case):
					_UpperCamelCase   :		int			=						first_field.items()
					_UpperCamelCase   :		Union[str, Any]			=						True
				else:
					try:
						_UpperCamelCase   :		str			=						iter(__snake_case)
						_UpperCamelCase   :		Dict			=						True
					except TypeError:
						_UpperCamelCase   :		Optional[Any]			=						False

            # if we provided an iterator as first field and the iterator is a (key, value) iterator
            # set the associated fields
				if first_field_iterator:
					for idx, element in enumerate(__snake_case):
						if (
						    not isinstance(__snake_case	,       (list, tuple))
						    or not len(__snake_case) == 2
						    or not isinstance(element[0]	,       __snake_case)
						):
							if idx == 0:
								# If we do not have an iterator of key/values, set it as attribute
								_UpperCamelCase   :		Optional[int]			=						first_field
							else:
								# If we have a mixed iterator, raise an error
								raise ValueError(
								    f'''Cannot set key/value for {element}. It needs to be a tuple (key, value).''')
							break
						setattr(self	,       element[0]	,       element[1])
						if element[1] is not None:
							_UpperCamelCase   :		Dict			=						element[1]
				elif first_field is not None:
					_UpperCamelCase   :		List[Any]			=						first_field
			else:
				for field in class_fields:
					_UpperCamelCase   :		List[str]			=						getattr(self	,       field.name)
					if v is not None:
						_UpperCamelCase   :		Any			=						v


		def __delitem__(				self	,       *__snake_case	,       **__snake_case):
			raise Exception(f'''You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.''')


		def 		A__					(				self	,       *__snake_case	,       **__snake_case):
			raise Exception(f'''You cannot use ``setdefault`` on a {self.__class__.__name__} instance.''')


		def 		A__					(				self	,       *__snake_case	,       **__snake_case):
			raise Exception(f'''You cannot use ``pop`` on a {self.__class__.__name__} instance.''')


		def 		A__					(				self	,       *__snake_case	,       **__snake_case):
			raise Exception(f'''You cannot use ``update`` on a {self.__class__.__name__} instance.''')


		def __getitem__(				self	,       __snake_case):
			if isinstance(__snake_case	,       __snake_case):
				_UpperCamelCase   :		int			=						dict(self.items())
				return inner_dict[k]
			else:
				return self.to_tuple()[k]


		def __setattr__(				self	,       __snake_case	,       __snake_case):
			if name in self.keys() and value is not None:
				# Don't call self.__setitem__ to avoid recursion errors
				super().__setitem__(__snake_case	,       __snake_case)
			super().__setattr__(__snake_case	,       __snake_case)


		def __setitem__(				self	,       __snake_case	,       __snake_case):
			# Will raise a KeyException if needed
			super().__setitem__(__snake_case	,       __snake_case)
			# Don't call self.__setattr__ to avoid recursion errors
			super().__setattr__(__snake_case	,       __snake_case)






		def 		A__					(				self):
			return tuple(self[k] for k in self.keys())







class 	lowercase    (				_lowercase    ,							_lowercase							):


		"""simple docstring"""




		@classmethod
		def 		A__					(				cls	,       __snake_case):
			raise ValueError(
			    f'''{value} is not a valid {cls.__name__}, please select one of {list(cls._valueamember_map_.keys())}''')







class 	lowercase    (				_lowercase							):


		"""simple docstring"""




		a__					       =  "longest"
		a__					       =  "max_length"
		a__					       =  "do_not_pad"







class 	lowercase    (				_lowercase							):


		"""simple docstring"""




		a__					       =  "pt"
		a__					       =  "tf"
		a__					       =  "np"
		a__					       =  "jax"







class 	lowercase    :


		"""simple docstring"""




		def __init__(				self	,       __snake_case):
			_UpperCamelCase   :		Dict			=						context_managers
			_UpperCamelCase   :		str			=						ExitStack()


		def __enter__(				self):
			for context_manager in self.context_managers:
				self.stack.enter_context(__snake_case)






		def __exit__(				self	,       *__snake_case	,       **__snake_case):
			self.stack.__exit__(*__snake_case	,       **__snake_case)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Optional[Any]	)						->				Dict:




	'''simple docstring'''




	_UpperCamelCase   :		Optional[Any]			=						infer_framework(UpperCAmelCase_	)
	if framework == "tf":
		_UpperCamelCase   :		List[Any]			=						inspect.signature(model_class.call	)  # TensorFlow models
	elif framework == "pt":
		_UpperCamelCase   :		str			=						inspect.signature(model_class.forward	)  # PyTorch models
	else:
		_UpperCamelCase   :		Dict			=						inspect.signature(model_class.__call__	)  # Flax models

	for p in signature.parameters:
		if p == "return_loss" and signature.parameters[p].default is True:
			return True

	return False






def 					lowerCamelCase_     (							UpperCAmelCase_							:     int	)						->				List[Any]:




	'''simple docstring'''




	_UpperCamelCase   :		Union[str, Any]			=						model_class.__name__
	_UpperCamelCase   :		str			=						infer_framework(UpperCAmelCase_	)
	if framework == "tf":
		_UpperCamelCase   :		int			=						inspect.signature(model_class.call	)  # TensorFlow models
	elif framework == "pt":
		_UpperCamelCase   :		List[Any]			=						inspect.signature(model_class.forward	)  # PyTorch models
	else:
		_UpperCamelCase   :		Dict			=						inspect.signature(model_class.__call__	)  # Flax models

	if "QuestionAnswering" in model_name:
		return [p for p in signature.parameters if "label" in p or p in ("start_positions", "end_positions")]
	else:
		return [p for p in signature.parameters if "label" in p]






def 					lowerCamelCase_     (							UpperCAmelCase_							:     MutableMapping							,       UpperCAmelCase_							:     str = ""							,       UpperCAmelCase_							:     str = "."	)						->				Any:




	'''simple docstring'''




	def _flatten_dict(UpperCAmelCase_							:     Optional[int]							,       UpperCAmelCase_							:     Optional[Any]=""							,       UpperCAmelCase_							:     Any="."	):
		for k, v in d.items():
			_UpperCamelCase   :		Tuple			=						str(UpperCAmelCase_	) + delimiter + str(UpperCAmelCase_	) if parent_key else k
			if v and isinstance(UpperCAmelCase_							,       UpperCAmelCase_	):
				yield from flatten_dict(UpperCAmelCase_							,       UpperCAmelCase_							,       delimiter=UpperCAmelCase_	).items()
			else:
				yield key, v

	return dict(_flatten_dict(UpperCAmelCase_							,       UpperCAmelCase_							,       UpperCAmelCase_	)	)






@contextmanager
def 					lowerCamelCase_     (							UpperCAmelCase_							:     Tuple							,       UpperCAmelCase_							:     bool = False	)						->				Dict:




	'''simple docstring'''




	if use_temp_dir:
		with tempfile.TemporaryDirectory() as tmp_dir:
			yield tmp_dir
	else:
		yield working_dir






def 					lowerCamelCase_     (							UpperCAmelCase_							:     List[Any]							,       UpperCAmelCase_							:     str=None	)						->				str:




	'''simple docstring'''




	if is_numpy_array(UpperCAmelCase_	):
		return np.transpose(UpperCAmelCase_							,       axes=UpperCAmelCase_	)
	elif is_torch_tensor(UpperCAmelCase_	):
		return array.T if axes is None else array.permute(*UpperCAmelCase_	)
	elif is_tf_tensor(UpperCAmelCase_	):
		import tensorflow as tf

		return tf.transpose(UpperCAmelCase_							,       perm=UpperCAmelCase_	)
	elif is_jax_tensor(UpperCAmelCase_	):
		return jnp.transpose(UpperCAmelCase_							,       axes=UpperCAmelCase_	)
	else:
		raise ValueError(F'''Type not supported for transpose: {type(UpperCAmelCase_	)}.'''	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     List[Any]							,       UpperCAmelCase_							:     str	)						->				Union[str, Any]:




	'''simple docstring'''




	if is_numpy_array(UpperCAmelCase_	):
		return np.reshape(UpperCAmelCase_							,       UpperCAmelCase_	)
	elif is_torch_tensor(UpperCAmelCase_	):
		return array.reshape(*UpperCAmelCase_	)
	elif is_tf_tensor(UpperCAmelCase_	):
		import tensorflow as tf

		return tf.reshape(UpperCAmelCase_							,       UpperCAmelCase_	)
	elif is_jax_tensor(UpperCAmelCase_	):
		return jnp.reshape(UpperCAmelCase_							,       UpperCAmelCase_	)
	else:
		raise ValueError(F'''Type not supported for reshape: {type(UpperCAmelCase_	)}.'''	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Optional[Any]							,       UpperCAmelCase_							:     str=None	)						->				Any:




	'''simple docstring'''




	if is_numpy_array(UpperCAmelCase_	):
		return np.squeeze(UpperCAmelCase_							,       axis=UpperCAmelCase_	)
	elif is_torch_tensor(UpperCAmelCase_	):
		return array.squeeze() if axis is None else array.squeeze(dim=UpperCAmelCase_	)
	elif is_tf_tensor(UpperCAmelCase_	):
		import tensorflow as tf

		return tf.squeeze(UpperCAmelCase_							,       axis=UpperCAmelCase_	)
	elif is_jax_tensor(UpperCAmelCase_	):
		return jnp.squeeze(UpperCAmelCase_							,       axis=UpperCAmelCase_	)
	else:
		raise ValueError(F'''Type not supported for squeeze: {type(UpperCAmelCase_	)}.'''	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     List[Any]							,       UpperCAmelCase_							:     str	)						->				Optional[int]:




	'''simple docstring'''




	if is_numpy_array(UpperCAmelCase_	):
		return np.expand_dims(UpperCAmelCase_							,       UpperCAmelCase_	)
	elif is_torch_tensor(UpperCAmelCase_	):
		return array.unsqueeze(dim=UpperCAmelCase_	)
	elif is_tf_tensor(UpperCAmelCase_	):
		import tensorflow as tf

		return tf.expand_dims(UpperCAmelCase_							,       axis=UpperCAmelCase_	)
	elif is_jax_tensor(UpperCAmelCase_	):
		return jnp.expand_dims(UpperCAmelCase_							,       axis=UpperCAmelCase_	)
	else:
		raise ValueError(F'''Type not supported for expand_dims: {type(UpperCAmelCase_	)}.'''	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     int	)						->				Any:




	'''simple docstring'''




	if is_numpy_array(UpperCAmelCase_	):
		return np.size(UpperCAmelCase_	)
	elif is_torch_tensor(UpperCAmelCase_	):
		return array.numel()
	elif is_tf_tensor(UpperCAmelCase_	):
		import tensorflow as tf

		return tf.size(UpperCAmelCase_	)
	elif is_jax_tensor(UpperCAmelCase_	):
		return array.size
	else:
		raise ValueError(F'''Type not supported for expand_dims: {type(UpperCAmelCase_	)}.'''	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Any							,       UpperCAmelCase_							:     Any	)						->				Optional[int]:




	'''simple docstring'''




	for key, value in auto_map.items():
		if isinstance(UpperCAmelCase_							,       (tuple, list)	):
			_UpperCamelCase   :		Optional[int]			=						[F'''{repo_id}--{v}''' if (v is not None and '--' not in v) else v for v in value]
		elif value is not None and "--" not in value:
			_UpperCamelCase   :		int			=						F'''{repo_id}--{value}'''

	return auto_map







def 					lowerCamelCase_     (							UpperCAmelCase_							:     int	)						->				List[str]:




	'''simple docstring'''




	for base_class in inspect.getmro(UpperCAmelCase_	):
		_UpperCamelCase   :		List[str]			=						base_class.__module__
		_UpperCamelCase   :		Optional[Any]			=						base_class.__name__
		if module.startswith('tensorflow'	) or module.startswith('keras'	) or name == "TFPreTrainedModel":
			return "tf"
		elif module.startswith('torch'	) or name == "PreTrainedModel":
			return "pt"
		elif module.startswith('flax'	) or module.startswith('jax'	) or name == "FlaxPreTrainedModel":
			return "flax"
	else:
		raise TypeError(F'''Could not infer framework from class {model_class}.'''	)







lowerCAmelCase__								=		range(2, 2_0 + 1)
lowerCAmelCase__								=		[1_0**k for k in range(ks[-1] + 1)]
lowerCAmelCase__								=		{}






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Optional[Any]							,       UpperCAmelCase_							:     List[str]							,       UpperCAmelCase_							:     Any							,       UpperCAmelCase_							:     int	)						->				Tuple:




	'''simple docstring'''




	_UpperCamelCase   :		Dict			=						sum(a_i[j] for j in range(UpperCAmelCase_							,       len(UpperCAmelCase_	)	)	)
	_UpperCamelCase   :		Optional[int]			=						sum(a_i[j] * base[j] for j in range(min(len(UpperCAmelCase_	)							,       UpperCAmelCase_	)	)	)

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

	_UpperCamelCase   :		Union[str, Any]			=						memo.get(UpperCAmelCase_	)

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

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

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

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

	_UpperCamelCase   :		List[str]			=						sub_memo[c]

	# keep jumps sorted by # of terms skipped
	_UpperCamelCase   :		Union[str, 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 					lowerCamelCase_     (							UpperCAmelCase_							:     int							,       UpperCAmelCase_							:     Dict							,       UpperCAmelCase_							:     Any							,       UpperCAmelCase_							:     Any	)						->				Dict:




	'''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)
	_UpperCamelCase   :		Any			=						i
	_UpperCamelCase	,		_UpperCamelCase	,		_UpperCamelCase   :		Any			=						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   :		Union[str, Any]			=						ds_c + ds_b
		diff += addend
		_UpperCamelCase   :		Union[str, 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 					lowerCamelCase_     (							UpperCAmelCase_							:     Union[str, Any]							,       UpperCAmelCase_							:     Optional[int]							,       UpperCAmelCase_							:     Any	)						->				Dict:




	'''simple docstring'''




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

		if addend == 0:
			break

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






def 					lowerCamelCase_     (							UpperCAmelCase_							:     int = 1_0**1_5	)						->				int:




	'''simple docstring'''




	_UpperCamelCase   :		Optional[Any]			=						[1]
	_UpperCamelCase   :		Optional[int]			=						1
	_UpperCamelCase   :		int			=						0
	while True:
		_UpperCamelCase	,		_UpperCamelCase   :		List[Any]			=						next_term(UpperCAmelCase_							,       2_0							,       i + dn							,       UpperCAmelCase_	)
		dn += terms_jumped
		if dn == n - i:
			break

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


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




