






"""simple docstring"""





A__					: List[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   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	Optional[int]:
    """simple docstring"""

    UpperCamelCase__         =    sum(a_i[j] for j in range(SCREAMING_SNAKE_CASE ,	len(SCREAMING_SNAKE_CASE					)					)					)
    UpperCamelCase__         =    sum(a_i[j] * base[j] for j in range(min(len(SCREAMING_SNAKE_CASE					) ,	SCREAMING_SNAKE_CASE					)					)					)

    UpperCamelCase__       ,						UpperCamelCase__         =    0, 0
    UpperCamelCase__         =    n - i

    UpperCamelCase__         =    memo.get(SCREAMING_SNAKE_CASE					)

    if sub_memo is not None:
        UpperCamelCase__         =    sub_memo.get(SCREAMING_SNAKE_CASE					)

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

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

        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__       ,						UpperCamelCase__         =    next_term(SCREAMING_SNAKE_CASE ,	k - 1 ,	i + dn ,	SCREAMING_SNAKE_CASE					)
            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__         =    compute(SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	i + dn ,	SCREAMING_SNAKE_CASE					)
        diff += _diff
        dn += terms_jumped

    UpperCamelCase__         =    sub_memo[c]

    # keep jumps sorted by # of terms skipped
    UpperCamelCase__         =    0
    while j < len(SCREAMING_SNAKE_CASE					):
        if jumps[j][1] > dn:
            break
        j += 1

    # cache the jump for this value digitsum(b) and c
    sub_memo[c].insert(SCREAMING_SNAKE_CASE ,	(diff, dn, k)					)
    return (diff, dn)







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	Optional[int]:
    """simple docstring"""

    if i >= n:
        return 0, i
    if k > len(SCREAMING_SNAKE_CASE					):
        a_i.extend([0 for _ in range(k - len(SCREAMING_SNAKE_CASE					)					)]					)

    # note: a_i -> b * 10^k + c
    # ds_b -> digitsum(b)
    # ds_c -> digitsum(c)
    UpperCamelCase__         =    i
    UpperCamelCase__       ,						UpperCamelCase__       ,						UpperCamelCase__         =    0, 0, 0
    for j in range(len(SCREAMING_SNAKE_CASE					)					):
        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(SCREAMING_SNAKE_CASE					):
            UpperCamelCase__         =    a_i[j] + addend
            UpperCamelCase__       ,						UpperCamelCase__         =    divmod(SCREAMING_SNAKE_CASE ,	10					)

            ds_c += a_i[j]

        if addend > 0:
            break

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







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE ,	SCREAMING_SNAKE_CASE					)					->	str:
    """simple docstring"""

    for j in range(SCREAMING_SNAKE_CASE ,	len(SCREAMING_SNAKE_CASE					)					):
        UpperCamelCase__         =    digits[j] + addend
        if s >= 10:
            UpperCamelCase__       ,						UpperCamelCase__         =    divmod(SCREAMING_SNAKE_CASE ,	10					)
            UpperCamelCase__         =    addend // 10 + quotient
        else:
            UpperCamelCase__         =    s
            UpperCamelCase__         =    addend // 10

        if addend == 0:
            break

    while addend > 0:
        UpperCamelCase__       ,						UpperCamelCase__         =    divmod(SCREAMING_SNAKE_CASE ,	10					)
        digits.append(SCREAMING_SNAKE_CASE					)







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE = 10**15					)					->	int:
    """simple docstring"""

    UpperCamelCase__         =    [1]
    UpperCamelCase__         =    1
    UpperCamelCase__         =    0
    while True:
        UpperCamelCase__       ,						UpperCamelCase__         =    next_term(SCREAMING_SNAKE_CASE ,	20 ,	i + dn ,	SCREAMING_SNAKE_CASE					)
        dn += terms_jumped
        if dn == n - i:
            break

    UpperCamelCase__         =    0
    for j in range(len(SCREAMING_SNAKE_CASE					)					):
        a_n += digits[j] * 10**j
    return a_n


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











"""simple docstring"""





import PIL.Image
import PIL.ImageOps
from packaging import version
from PIL import Image


if version.parse(version.parse(PIL.__version__).base_version) >= version.parse("""9.1.0"""):
  A__					: str=	{
      """linear""": PIL.Image.Resampling.BILINEAR,
      """bilinear""": PIL.Image.Resampling.BILINEAR,
      """bicubic""": PIL.Image.Resampling.BICUBIC,
      """lanczos""": PIL.Image.Resampling.LANCZOS,
      """nearest""": PIL.Image.Resampling.NEAREST,
  }
else:
  A__					: str=	{
      """linear""": PIL.Image.LINEAR,
      """bilinear""": PIL.Image.BILINEAR,
      """bicubic""": PIL.Image.BICUBIC,
      """lanczos""": PIL.Image.LANCZOS,
      """nearest""": PIL.Image.NEAREST,
  }







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE					)					->	int:
    """simple docstring"""

    UpperCamelCase__         =    (images / 2 + 0.5).clamp(0 ,	1					)
    UpperCamelCase__         =    images.cpu().permute(0 ,	2 ,	3 ,	1					).float().numpy()
    UpperCamelCase__         =    numpy_to_pil(SCREAMING_SNAKE_CASE					)
    return images







def   lowerCAmelCase_( SCREAMING_SNAKE_CASE					)					->	Optional[int]:
    """simple docstring"""

    if images.ndim == 3:
        UpperCamelCase__         =    images[None, ...]
    UpperCamelCase__         =    (images * 2_55).round().astype('uint8'					)
    if images.shape[-1] == 1:
        # special case for grayscale (single channel) images
        UpperCamelCase__         =    [Image.fromarray(image.squeeze() ,	mode='L'					) for image in images]
    else:
        UpperCamelCase__         =    [Image.fromarray(SCREAMING_SNAKE_CASE					) for image in images]

    return pil_images




