






'''simple docstring'''







import os
import sys
import unittest


_A	:			List[str]         =os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, '''utils'''))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
_A	:			Dict         =os.path.join(git_repo_path, '''src''', '''transformers''')

_A	:			Dict         ='''
{0} = None
'''

_A	:			Dict         ='''
class {0}(metaclass=DummyObject):
    _backends = {1}

    def __init__(self, *args, **kwargs):
        requires_backends(self, {1})
'''


_A	:			List[str]         ='''
def {0}(*args, **kwargs):
    requires_backends({0}, {1})
'''

class _lowercase	(				unittest.TestCase		):




							def 		lowerCamelCase_				(							self:				str     ):
														lowerCamelCase__					:	int         =       find_backend("""    _import_structure[\"models.albert\"].append(\"AlbertTokenizerFast\")"""     )
														self.assertIsNone(UpperCamelCase__     )

														lowerCamelCase__					:	Optional[Any]         =       find_backend("""    if not is_tokenizers_available():"""     )
														self.assertEqual(UpperCamelCase__			,							"""tokenizers"""     )

														lowerCamelCase__					:	Tuple         =       find_backend("""    if not is_tensorflow_text_available():"""     )
														self.assertEqual(UpperCamelCase__			,							"""tensorflow_text"""     )

														lowerCamelCase__					:	Dict         =       find_backend("""    if not (is_sentencepiece_available() and is_tokenizers_available()):"""     )
														self.assertEqual(UpperCamelCase__			,							"""sentencepiece_and_tokenizers"""     )

														lowerCamelCase__					:	Union[str, Any]         =       find_backend(
														    """    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"""     )
														self.assertEqual(UpperCamelCase__			,							"""sentencepiece_and_tensorflow_text"""     )

														lowerCamelCase__					:	str         =       find_backend(
														    """    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):"""     )
														self.assertEqual(UpperCamelCase__			,							"""sentencepiece_and_tokenizers_and_vision"""     )




							def 		lowerCamelCase_				(							self:				Tuple     ):
														lowerCamelCase__					:	Tuple         =       read_init()
														# We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
														self.assertIn("""torch"""			,							UpperCamelCase__     )
														self.assertIn("""tensorflow_text"""			,							UpperCamelCase__     )
														self.assertIn("""sentencepiece_and_tokenizers"""			,							UpperCamelCase__     )

														# Likewise, we can't assert on the exact content of a key
														self.assertIn("""BertModel"""			,							objects["""torch"""]     )
														self.assertIn("""TFBertModel"""			,							objects["""tf"""]     )
														self.assertIn("""FlaxBertModel"""			,							objects["""flax"""]     )
														self.assertIn("""BertModel"""			,							objects["""torch"""]     )
														self.assertIn("""TFBertTokenizer"""			,							objects["""tensorflow_text"""]     )
														self.assertIn("""convert_slow_tokenizer"""			,							objects["""sentencepiece_and_tokenizers"""]     )




							def 		lowerCamelCase_				(							self:				Dict     ):
														lowerCamelCase__					:	Tuple         =       create_dummy_object("""CONSTANT"""			,							"""'torch'"""     )
														self.assertEqual(UpperCamelCase__			,							"""\nCONSTANT = None\n"""     )

														lowerCamelCase__					:	List[str]         =       create_dummy_object("""function"""			,							"""'torch'"""     )
														self.assertEqual(
														    UpperCamelCase__			,							"""\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"""     )

														lowerCamelCase__					:	List[str]         =       """
class FakeClass(metaclass=DummyObject):
    _backends = 'torch'

    def __init__(self, *args, **kwargs):
        requires_backends(self, 'torch')
"""
														lowerCamelCase__					:	int         =       create_dummy_object("""FakeClass"""			,							"""'torch'"""     )
														self.assertEqual(UpperCamelCase__			,							UpperCamelCase__     )




							def 		lowerCamelCase_				(							self:				Tuple     ):
														lowerCamelCase__					:	List[Any]         =       """# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, [\"torch\"])


class FakeClass(metaclass=DummyObject):
    _backends = [\"torch\"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, [\"torch\"])
"""
														lowerCamelCase__					:	Any         =       create_dummy_files({"""torch""": ["""CONSTANT""", """function""", """FakeClass"""]}     )
														self.assertEqual(dummy_files["""torch"""]			,							UpperCamelCase__     )









'''simple docstring'''







_A	:			Union[str, Any]         =range(2, 20 + 1)
_A	:			List[str]         =[10**k for k in range(ks[-1] + 1)]
_A	:			dict[int, dict[int, list[list[int]]]]         ={}





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )      ->       List[Any]:
							lowerCamelCase__					:	List[str]         =       sum(a_i[j] for j in range(UpperCamelCase				,			len(UpperCamelCase      )      )      )
							lowerCamelCase__					:	int         =       sum(a_i[j] * base[j] for j in range(min(len(UpperCamelCase      )				,			UpperCamelCase      )      )      )

							lowerCamelCase__  ,		lowerCamelCase__					:	Dict         =       0, 0
							lowerCamelCase__					:	List[str]         =       n - i

							lowerCamelCase__					:	Optional[Any]         =       memo.get(UpperCamelCase      )

							if sub_memo is not None:
														lowerCamelCase__					:	str         =       sub_memo.get(UpperCamelCase      )

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

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

														else:
																					lowerCamelCase__					:	Any         =       []
							else:
														lowerCamelCase__					:	str         =       {c: []}
														lowerCamelCase__					:	Tuple         =       sub_memo

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

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

							lowerCamelCase__					:	str         =       sub_memo[c]

							# keep jumps sorted by # of terms skipped
							lowerCamelCase__					:	List[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  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )      ->       List[Any]:
							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)
							lowerCamelCase__					:	Optional[Any]         =       i
							lowerCamelCase__  ,		lowerCamelCase__  ,		lowerCamelCase__					:	Optional[int]         =       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
														lowerCamelCase__					:	Optional[int]         =       ds_c + ds_b
														diff += addend
														lowerCamelCase__					:	int         =       0
														for j in range(UpperCamelCase      ):
																					lowerCamelCase__					:	str         =       a_i[j] + addend
																					lowerCamelCase__  ,		lowerCamelCase__					:	int         =       divmod(UpperCamelCase				,			10      )

																					ds_c += a_i[j]

														if addend > 0:
																					break

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





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase				,			UpperCamelCase				,			UpperCamelCase      )      ->       str:
							for j in range(UpperCamelCase				,			len(UpperCamelCase      )      ):
														lowerCamelCase__					:	List[Any]         =       digits[j] + addend
														if s >= 10:
																					lowerCamelCase__  ,		lowerCamelCase__					:	Union[str, Any]         =       divmod(UpperCamelCase				,			10      )
																					lowerCamelCase__					:	Any         =       addend // 10 + quotient
														else:
																					lowerCamelCase__					:	Any         =       s
																					lowerCamelCase__					:	Optional[Any]         =       addend // 10

														if addend == 0:
																					break

							while addend > 0:
														lowerCamelCase__  ,		lowerCamelCase__					:	Any         =       divmod(UpperCamelCase				,			10      )
														digits.append(UpperCamelCase      )





def  SCREAMING_SNAKE_CASE_       (UpperCamelCase = 10**15      )      ->       int:
							lowerCamelCase__					:	Any         =       [1]
							lowerCamelCase__					:	List[str]         =       1
							lowerCamelCase__					:	Tuple         =       0
							while True:
														lowerCamelCase__  ,		lowerCamelCase__					:	Any         =       next_term(UpperCamelCase				,			20				,			i + dn				,			UpperCamelCase      )
														dn += terms_jumped
														if dn == n - i:
																					break

							lowerCamelCase__					:	Union[str, Any]         =       0
							for j in range(len(UpperCamelCase      )      ):
														a_n += digits[j] * 10**j
							return a_n


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

