
from math import factorial

lowerCamelCase      ={str(digit): factorial(digit) for digit in range(1_0)}


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__		):
      if not isinstance(UpperCamelCase__ ,		UpperCamelCase__		):
            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(UpperCamelCase__		)		)


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__ = 6_0 ,		UpperCamelCase__ = 1_0_0_0_0_0_0		):

      if not isinstance(UpperCamelCase__ ,		UpperCamelCase__		) or not isinstance(UpperCamelCase__ ,		UpperCamelCase__		):
            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
      UpperCamelCase__    :   Dict					=				0
      # the cached sizes of the previous chains
      UpperCamelCase__    :   dict[int, int]					=				{}

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

            # Stop computing the chain when you find a cached size, a repeating item or the
            # length is greater then the desired one.
            UpperCamelCase__    :   Any					=				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(UpperCamelCase__		)
                  chain_set_length += 1
                  UpperCamelCase__    :   List[str]					=				digit_factorial_sum(UpperCamelCase__		)

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

            UpperCamelCase__    :   List[str]					=				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()}''')




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCamelCase      ={
    "configuration_clipseg": [
        "CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "CLIPSegConfig",
        "CLIPSegTextConfig",
        "CLIPSegVisionConfig",
    ],
    "processing_clipseg": ["CLIPSegProcessor"],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCamelCase      =[
        "CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST",
        "CLIPSegModel",
        "CLIPSegPreTrainedModel",
        "CLIPSegTextModel",
        "CLIPSegVisionModel",
        "CLIPSegForImageSegmentation",
    ]

if TYPE_CHECKING:
    from .configuration_clipseg import (
        CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP,
        CLIPSegConfig,
        CLIPSegTextConfig,
        CLIPSegVisionConfig,
    )
    from .processing_clipseg import CLIPSegProcessor

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_clipseg import (
            CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST,
            CLIPSegForImageSegmentation,
            CLIPSegModel,
            CLIPSegPreTrainedModel,
            CLIPSegTextModel,
            CLIPSegVisionModel,
        )

else:
    import sys

    lowerCamelCase      =_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


