


SCREAMING_SNAKE_CASE :   List[str]							      =				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:
    _lowercase :							Dict   	=	sum(a_i[j] for j in range(lowerCamelCase_							,				len(lowerCamelCase_				)				)				)
    _lowercase :							List[str]   	=	sum(a_i[j] * base[j] for j in range(min(len(lowerCamelCase_				)							,				lowerCamelCase_				)				)				)

    _lowercase	,       _lowercase :							Optional[Any]   	=	0, 0
    _lowercase :							Optional[Any]   	=	n - i

    _lowercase :							Dict   	=	memo.get(lowerCamelCase_				)

    if sub_memo is not None:
        _lowercase :							List[Any]   	=	sub_memo.get(lowerCamelCase_				)

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

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

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

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

    # keep jumps sorted by # of terms skipped
    _lowercase :							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_				)					->		List[str]:
    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)
    _lowercase :							Any   	=	i
    _lowercase	,       _lowercase	,       _lowercase :							str   	=	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
        _lowercase :							List[str]   	=	ds_c + ds_b
        diff += addend
        _lowercase :							List[Any]   	=	0
        for j in range(lowerCamelCase_				):
            _lowercase :							int   	=	a_i[j] + addend
            _lowercase	,       _lowercase :							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        UpperCamelCase_(   lowerCamelCase_							,				lowerCamelCase_							,				lowerCamelCase_				)					->		Tuple:
    for j in range(lowerCamelCase_							,				len(lowerCamelCase_				)				):
        _lowercase :							int   	=	digits[j] + addend
        if s >= 10:
            _lowercase	,       _lowercase :							Any   	=	divmod(lowerCamelCase_							,				10				)
            _lowercase :							Dict   	=	addend // 10 + quotient
        else:
            _lowercase :							str   	=	s
            _lowercase :							Any   	=	addend // 10

        if addend == 0:
            break

    while addend > 0:
        _lowercase	,       _lowercase :							Optional[int]   	=	divmod(lowerCamelCase_							,				10				)
        digits.append(lowerCamelCase_				)



def        UpperCamelCase_(   lowerCamelCase_ = 10**15				)					->		int:
    _lowercase :							Union[str, Any]   	=	[1]
    _lowercase :							List[Any]   	=	1
    _lowercase :							Union[str, Any]   	=	0
    while True:
        _lowercase	,       _lowercase :							Dict   	=	next_term(lowerCamelCase_							,				20							,				i + dn							,				lowerCamelCase_				)
        dn += terms_jumped
        if dn == n - i:
            break

    _lowercase :							List[str]   	=	0
    for j in range(len(lowerCamelCase_				)				):
        a_n += digits[j] * 10**j
    return a_n


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






def        UpperCamelCase_(   lowerCamelCase_							,				lowerCamelCase_				)					->		bool:
    return numa ^ numa < 0


if __name__ == "__main__":
 import doctest

 doctest.testmod()


