



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




def 	__UpperCamelCase	(  _lowerCAmelCase      ,     _lowerCAmelCase      ,     _lowerCAmelCase      ,     _lowerCAmelCase		)       ->  int:



    """simple docstring"""






    A :       int          =   sum(a_i[j] for j in range(_lowerCAmelCase      ,     len(_lowerCAmelCase		)		)		)
    A :       Optional[Any]          =   sum(a_i[j] * base[j] for j in range(min(len(_lowerCAmelCase		)      ,     _lowerCAmelCase		)		)		)

    A     ,							A :       Dict          =   0, 0
    A :       Tuple          =   n - i

    A :       Union[str, Any]          =   memo.get(_lowerCAmelCase		)

    if sub_memo is not None:
        A :       int          =   sub_memo.get(_lowerCAmelCase		)

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

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

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

    A :       Union[str, Any]          =   sub_memo[c]

    # keep jumps sorted by # of terms skipped
    A :       List[str]          =   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 	__UpperCamelCase	(  _lowerCAmelCase      ,     _lowerCAmelCase      ,     _lowerCAmelCase      ,     _lowerCAmelCase		)       ->  Union[str, Any]:



    """simple docstring"""






    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)
    A :       Union[str, Any]          =   i
    A     ,							A     ,							A :       List[Any]          =   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
        A :       Optional[int]          =   ds_c + ds_b
        diff += addend
        A :       Optional[int]          =   0
        for j in range(_lowerCAmelCase		):
            A :       List[str]          =   a_i[j] + addend
            A     ,							A :       List[str]          =   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 	__UpperCamelCase	(  _lowerCAmelCase      ,     _lowerCAmelCase      ,     _lowerCAmelCase		)       ->  Tuple:



    """simple docstring"""






    for j in range(_lowerCAmelCase      ,     len(_lowerCAmelCase		)		):
        A :       str          =   digits[j] + addend
        if s >= 10:
            A     ,							A :       Any          =   divmod(_lowerCAmelCase      ,     10		)
            A :       Any          =   addend // 10 + quotient
        else:
            A :       Dict          =   s
            A :       Tuple          =   addend // 10

        if addend == 0:
            break

    while addend > 0:
        A     ,							A :       Any          =   divmod(_lowerCAmelCase      ,     10		)
        digits.append(_lowerCAmelCase		)




def 	__UpperCamelCase	(  _lowerCAmelCase = 10**15		)       ->  int:



    """simple docstring"""






    A :       List[Any]          =   [1]
    A :       Tuple          =   1
    A :       str          =   0
    while True:
        A     ,							A :       Dict          =   next_term(_lowerCAmelCase      ,     20      ,     i + dn      ,     _lowerCAmelCase		)
        dn += terms_jumped
        if dn == n - i:
            break

    A :       Dict          =   0
    for j in range(len(_lowerCAmelCase		)		):
        a_n += digits[j] * 10**j
    return a_n


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







import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
     import jax.numpy as jnp

     from transformers.models.albert.modeling_flax_albert import (
         FlaxAlbertForMaskedLM,
         FlaxAlbertForMultipleChoice,
         FlaxAlbertForPreTraining,
         FlaxAlbertForQuestionAnswering,
         FlaxAlbertForSequenceClassification,
         FlaxAlbertForTokenClassification,
         FlaxAlbertModel,
     )






class SCREAMING_SNAKE_CASE__     (		unittest.TestCase    ):




    '''simple docstring'''






    def __init__(       self,		lowerCamelCase__,		lowerCamelCase__=13,		lowerCamelCase__=7,		lowerCamelCase__=True,		lowerCamelCase__=True,		lowerCamelCase__=True,		lowerCamelCase__=True,		lowerCamelCase__=99,		lowerCamelCase__=32,		lowerCamelCase__=5,		lowerCamelCase__=4,		lowerCamelCase__=37,		lowerCamelCase__="gelu",		lowerCamelCase__=0.1,		lowerCamelCase__=0.1,		lowerCamelCase__=512,		lowerCamelCase__=16,		lowerCamelCase__=2,		lowerCamelCase__=0.02,		lowerCamelCase__=4,		):
        A :       List[str]          =   parent
        A :       Optional[int]          =   batch_size
        A :       Union[str, Any]          =   seq_length
        A :       Any          =   is_training
        A :       List[str]          =   use_attention_mask
        A :       Union[str, Any]          =   use_token_type_ids
        A :       Any          =   use_labels
        A :       str          =   vocab_size
        A :       Union[str, Any]          =   hidden_size
        A :       str          =   num_hidden_layers
        A :       List[Any]          =   num_attention_heads
        A :       Optional[int]          =   intermediate_size
        A :       Optional[Any]          =   hidden_act
        A :       Dict          =   hidden_dropout_prob
        A :       List[Any]          =   attention_probs_dropout_prob
        A :       Optional[int]          =   max_position_embeddings
        A :       int          =   type_vocab_size
        A :       str          =   type_sequence_label_size
        A :       List[Any]          =   initializer_range
        A :       str          =   num_choices






    def 			_lowerCAmelCase					(       self		):
        A :       Optional[int]          =   ids_tensor([self.batch_size, self.seq_length],		self.vocab_size		)

        A :       Union[str, Any]          =   None
        if self.use_attention_mask:
            A :       Optional[int]          =   random_attention_mask([self.batch_size, self.seq_length]		)

        A :       int          =   None
        if self.use_token_type_ids:
            A :       List[Any]          =   ids_tensor([self.batch_size, self.seq_length],		self.type_vocab_size		)

        A :       Optional[int]          =   AlbertConfig(
            vocab_size=self.vocab_size,		hidden_size=self.hidden_size,		num_hidden_layers=self.num_hidden_layers,		num_attention_heads=self.num_attention_heads,		intermediate_size=self.intermediate_size,		hidden_act=self.hidden_act,		hidden_dropout_prob=self.hidden_dropout_prob,		attention_probs_dropout_prob=self.attention_probs_dropout_prob,		max_position_embeddings=self.max_position_embeddings,		type_vocab_size=self.type_vocab_size,		is_decoder=lowerCamelCase__,		initializer_range=self.initializer_range,		)

        return config, input_ids, token_type_ids, attention_mask






    def 			_lowerCAmelCase					(       self		):
        A :       Dict          =   self.prepare_config_and_inputs()
        A     ,							A     ,							A     ,							A :       str          =   config_and_inputs
        A :       Union[str, Any]          =   {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
        return config, inputs_dict






@require_flax
class SCREAMING_SNAKE_CASE__     (		SCREAMING_SNAKE_CASE__ ,						unittest.TestCase    ):




    '''simple docstring'''






    __lowerCamelCase			: Any					=      (
        (
            FlaxAlbertModel,
            FlaxAlbertForPreTraining,
            FlaxAlbertForMaskedLM,
            FlaxAlbertForMultipleChoice,
            FlaxAlbertForQuestionAnswering,
            FlaxAlbertForSequenceClassification,
            FlaxAlbertForTokenClassification,
            FlaxAlbertForQuestionAnswering,
        )
        if is_flax_available()
        else ()
    )






    def 			_lowerCAmelCase					(       self		):
        A :       Dict          =   FlaxAlbertModelTester(self		)






    @slow
    def 			_lowerCAmelCase					(       self		):
        for model_class_name in self.all_model_classes:
            A :       Dict          =   model_class_name.from_pretrained("""albert-base-v2"""		)
            A :       Optional[int]          =   model(np.ones((1, 1)		)		)
            self.assertIsNotNone(lowerCamelCase__		)






@require_flax
class SCREAMING_SNAKE_CASE__     (		unittest.TestCase    ):




    '''simple docstring'''






    @slow
    def 			_lowerCAmelCase					(       self		):
        A :       Dict          =   FlaxAlbertModel.from_pretrained("""albert-base-v2"""		)
        A :       List[str]          =   np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
        A :       str          =   np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
        A :       Optional[int]          =   model(lowerCamelCase__,		attention_mask=lowerCamelCase__		)[0]
        A :       str          =   (1, 11, 768)
        self.assertEqual(output.shape,		lowerCamelCase__		)
        A :       Optional[int]          =   np.array(
            [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]		)

        self.assertTrue(jnp.allclose(output[:, 1:4, 1:4],		lowerCamelCase__,		atol=1e-4		)		)


