


'''simple docstring'''






from math import factorial

__A					:  Dict											=      {str(digit): factorial(digit) for digit in range(10)}







def 				UpperCamelCase_			(    A__					:   Tuple					):
  '''simple docstring'''





  if not isinstance(__snake_case							,    __snake_case					):
    raise TypeError("""Parameter number must be int"""					)

  if number < 0:
    raise ValueError("""Parameter number must be greater than or equal to 0"""					)

  # Converts number in string to iterate on its digits and adds its factorial.
  return sum(DIGIT_FACTORIAL[digit] for digit in str(__snake_case					)					)







def 				UpperCamelCase_			(    A__					:   Any = 60							,    A__					:   Tuple = 1_00_00_00					):
  '''simple docstring'''





  if not isinstance(__snake_case							,    __snake_case					) or not isinstance(__snake_case							,    __snake_case					):
    raise TypeError("""Parameters chain_length and number_limit must be int"""					)

  if chain_length <= 0 or number_limit <= 0:
    raise ValueError(
        """Parameters chain_length and number_limit must be greater than 0"""					)

  # the counter for the chains with the exact desired length
  lowerCAmelCase_			:      List[Any]			=   0
  # the cached sizes of the previous chains
  lowerCAmelCase_			:      Dict			=   {}

  for start_chain_element in range(1							,    __snake_case					):
    # The temporary set will contain the elements of the chain
    lowerCAmelCase_			:      List[str]			=   set()
    lowerCAmelCase_			:      List[Any]			=   0

    # Stop computing the chain when you find a cached size, a repeating item or the
    # length is greater then the desired one.
    lowerCAmelCase_			:      Dict			=   start_chain_element
    while (
        chain_element not in chain_sets_lengths
        and chain_element not in chain_set
        and chain_set_length <= chain_length
    ):
      chain_set.add(__snake_case					)
      chain_set_length += 1
      lowerCAmelCase_			:      List[str]			=   digit_factorial_sum(__snake_case					)

    if chain_element in chain_sets_lengths:
      chain_set_length += chain_sets_lengths[chain_element]

    lowerCAmelCase_			:      Dict			=   chain_set_length

    # If chain contains the exact amount of elements increase the counter
    if chain_set_length == chain_length:
      chains_counter += 1

  return chains_counter


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  print(F'''{solution()}''')







import gc
import unittest

from diffusers import FlaxStableDiffusionInpaintPipeline
from diffusers.utils import is_flax_available, load_image, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
  import jax
  import jax.numpy as jnp
  from flax.jax_utils import replicate
  from flax.training.common_utils import shard







@slow
@require_flax
class       lowerCamelCase__   (       unittest.TestCase):





     def      __A					(self       )     ->   List[Any]:
      # clean up the VRAM after each test
      super().tearDown()
      gc.collect()





     def      __A					(self       )     ->   Optional[Any]:
      _lowercase							      =load_image(
          '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
          '''/sd2-inpaint/init_image.png'''       )
      _lowercase							      =load_image(
          '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-inpaint/mask.png'''       )

      _lowercase							      ='''xvjiarui/stable-diffusion-2-inpainting'''
      _lowercase      ,    _lowercase							      =FlaxStableDiffusionInpaintPipeline.from_pretrained(UpperCAmelCase		,     safety_checker=UpperCAmelCase       )

      _lowercase							      ='''Face of a yellow cat, high resolution, sitting on a park bench'''

      _lowercase							      =jax.random.PRNGKey(0       )
      _lowercase							      =5_0

      _lowercase							      =jax.device_count()
      _lowercase							      =num_samples * [prompt]
      _lowercase							      =num_samples * [init_image]
      _lowercase							      =num_samples * [mask_image]
      _lowercase      ,    _lowercase      ,    _lowercase							      =pipeline.prepare_inputs(UpperCAmelCase		,     UpperCAmelCase		,     UpperCAmelCase       )

      # shard inputs and rng
      _lowercase							      =replicate(UpperCAmelCase       )
      _lowercase							      =jax.random.split(UpperCAmelCase		,     jax.device_count()       )
      _lowercase							      =shard(UpperCAmelCase       )
      _lowercase							      =shard(UpperCAmelCase       )
      _lowercase							      =shard(UpperCAmelCase       )

      _lowercase							      =pipeline(
          UpperCAmelCase		,     UpperCAmelCase		,     UpperCAmelCase		,     UpperCAmelCase		,     UpperCAmelCase		,     UpperCAmelCase		,     jit=UpperCAmelCase       )

      _lowercase							      =output.images.reshape(UpperCAmelCase		,     5_1_2		,     5_1_2		,     3       )

      _lowercase							      =images[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

      _lowercase							      =jnp.asarray(jax.device_get(image_slice.flatten()       )       )
      _lowercase							      =jnp.array(
          [0.361_1307, 0.3764_9736, 0.375_7408, 0.3821_3953, 0.3929_5167, 0.384_1631, 0.4155_4978, 0.413_7475, 0.421_7084]       )
      print(f"output_slice: {output_slice}"       )
      assert jnp.abs(output_slice - expected_slice       ).max() < 1e-2

