




'''simple docstring'''







_lowercase       						=			range(2, 20 + 1)
_lowercase       						=			[10**k for k in range(ks[-1] + 1)]
_lowercase       						=			{}

def    __UpperCamelCase	(	a    : Dict					,   a    : List[str]					,   a    : Dict					,   a    : Any     ) ->List[Any]:
 snake_case				=			sum(a_i[j] for j in range(a					,   len(a     )     )     )
 snake_case				=			sum(a_i[j] * base[j] for j in range(min(len(a     )					,   a     )     )     )

 snake_case				,		snake_case				=			0, 0
 snake_case				=			n - i

 snake_case				=			memo.get(a     )

 if sub_memo is not None:
  snake_case				=			sub_memo.get(a     )

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

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

  else:
   snake_case				=			[]
 else:
  snake_case				=			{c: []}
  snake_case				=			sub_memo

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

 if k > ks[0]:
  while True:
   # keep doing smaller jumps
   snake_case				,		snake_case				=			next_term(a					,   k - 1					,   i + dn					,   a     )
   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
  snake_case				,		snake_case				=			compute(a					,   a					,   i + dn					,   a     )
  diff += _diff
  dn += terms_jumped

 snake_case				=			sub_memo[c]

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

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

def    __UpperCamelCase	(	a    : List[str]					,   a    : List[str]					,   a    : List[Any]					,   a    : List[str]     ) ->List[str]:
 if i >= n:
  return 0, i
 if k > len(a     ):
  a_i.extend([0 for _ in range(k - len(a     )     )]     )

 # note: a_i -> b * 10^k + c
 # ds_b -> digitsum(b)
 # ds_c -> digitsum(c)
 snake_case				=			i
 snake_case				,		snake_case				,		snake_case				=			0, 0, 0
 for j in range(len(a     )     ):
  if j >= k:
   ds_b += a_i[j]
  else:
   ds_c += a_i[j]

 while i < n:
  i += 1
  snake_case				=			ds_c + ds_b
  diff += addend
  snake_case				=			0
  for j in range(a     ):
   snake_case				=			a_i[j] + addend
   snake_case				,		snake_case				=			divmod(a					,   10     )

   ds_c += a_i[j]

  if addend > 0:
   break

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

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

  if addend == 0:
   break

 while addend > 0:
  snake_case				,		snake_case				=			divmod(a					,   10     )
  digits.append(a     )

def    __UpperCamelCase	(	a    : int = 10**15     ) ->int:
 snake_case				=			[1]
 snake_case				=			1
 snake_case				=			0
 while True:
  snake_case				,		snake_case				=			next_term(a					,   20					,   i + dn					,   a     )
  dn += terms_jumped
  if dn == n - i:
   break

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


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








'''simple docstring'''







import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin
@skip_mps
class 			_lowercase						(       __a				,		__a				,		unittest.TestCase					):
     _UpperCAmelCase										=					IFInpaintingSuperResolutionPipeline
     _UpperCAmelCase										=					TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {'''width''', '''height'''}
     _UpperCAmelCase										=					TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({'''original_image'''}					)
     _UpperCAmelCase										=					PipelineTesterMixin.required_optional_params - {'''latents'''}







     def     UpperCamelCase			( self    ) ->	int:
      return self._get_superresolution_dummy_components()







     def     UpperCamelCase			( self    ,   A__    ,   A__=0    ) ->	Union[str, Any]:
      if str(A__    ).startswith('''mps'''    ):
       snake_case				=			torch.manual_seed(A__    )
      else:
       snake_case				=			torch.Generator(device=A__    ).manual_seed(A__    )

      snake_case				=			floats_tensor((1, 3, 16, 16)    ,   rng=random.Random(A__    )    ).to(A__    )
      snake_case				=			floats_tensor((1, 3, 32, 32)    ,   rng=random.Random(A__    )    ).to(A__    )
      snake_case				=			floats_tensor((1, 3, 32, 32)    ,   rng=random.Random(A__    )    ).to(A__    )

      snake_case				=			{
          '''prompt''': '''A painting of a squirrel eating a burger''',
          '''image''': image,
          '''original_image''': original_image,
          '''mask_image''': mask_image,
          '''generator''': generator,
          '''num_inference_steps''': 2,
          '''output_type''': '''numpy''',
      }

      return inputs







     @unittest.skipIf(
         torch_device != '''cuda''' or not is_xformers_available()    ,   reason='''XFormers attention is only available with CUDA and `xformers` installed'''    ,   )
     def     UpperCamelCase			( self    ) ->	List[Any]:
      self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3    )







     def     UpperCamelCase			( self    ) ->	Optional[Any]:
      self._test_save_load_optional_components()







     @unittest.skipIf(torch_device != '''cuda'''    ,   reason='''float16 requires CUDA'''    )
     def     UpperCamelCase			( self    ) ->	List[str]:
      # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
      super().test_save_load_floataa(expected_max_diff=1e-1    )







     def     UpperCamelCase			( self    ) ->	int:
      self._test_attention_slicing_forward_pass(expected_max_diff=1e-2    )







     def     UpperCamelCase			( self    ) ->	Optional[Any]:
      self._test_save_load_local()







     def     UpperCamelCase			( self    ) ->	Dict:
      self._test_inference_batch_single_identical(
          expected_max_diff=1e-2    ,   )

