

UpperCAmelCase__			:  Optional[int]					     =     {
    """0""": 1,
    """1""": 1,
    """2""": 2,
    """3""": 6,
    """4""": 24,
    """5""": 120,
    """6""": 720,
    """7""": 5_040,
    """8""": 40_320,
    """9""": 362_880,
}

UpperCAmelCase__			:  Dict					     =     {145: 145}

UpperCAmelCase__			:  Any					     =     {
    145: 0,
    169: 3,
    36_301: 3,
    1_454: 3,
    871: 2,
    45_361: 2,
    872: 2,
}






def        __lowercase   (  _A      )  ->    int:
      if n in CACHE_SUM_DIGIT_FACTORIALS:
            return CACHE_SUM_DIGIT_FACTORIALS[n]
      SCREAMING_SNAKE_CASE			:   Dict	  = sum(DIGIT_FACTORIALS[let] for let in str(_A      )      )
      SCREAMING_SNAKE_CASE			:   List[Any]	  = ret
      return ret






def        __lowercase   (  _A    ,     _A = None      )  ->    int:
      SCREAMING_SNAKE_CASE			:   Tuple	  = previous or set()
      if n in CHAIN_LENGTH_CACHE:
            return CHAIN_LENGTH_CACHE[n]
      SCREAMING_SNAKE_CASE			:   List[str]	  = sum_digit_factorials(_A      )
      if next_number in previous:
            SCREAMING_SNAKE_CASE			:   Tuple	  = 0
            return 0
      else:
            previous.add(_A      )
            SCREAMING_SNAKE_CASE			:   str	  = 1 + chain_length(_A    ,     _A      )
            SCREAMING_SNAKE_CASE			:   Dict	  = ret
            return ret






def        __lowercase   (  _A = 60    ,     _A = 1000000      )  ->    int:
      return sum(1 for i in range(1    ,     _A      ) if chain_length(_A      ) == num_terms      )


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







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase__			:  Optional[Any]					     =     {
    """configuration_musicgen""": [
        """MUSICGEN_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """MusicgenConfig""",
        """MusicgenDecoderConfig""",
    ],
    """processing_musicgen""": ["""MusicgenProcessor"""],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__			:  Any					     =     [
      """MUSICGEN_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """MusicgenForConditionalGeneration""",
      """MusicgenForCausalLM""",
      """MusicgenModel""",
      """MusicgenPreTrainedModel""",
  ]

if TYPE_CHECKING:
  from .configuration_musicgen import (
      MUSICGEN_PRETRAINED_CONFIG_ARCHIVE_MAP,
      MusicgenConfig,
      MusicgenDecoderConfig,
  )
  from .processing_musicgen import MusicgenProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_musicgen import (
        MUSICGEN_PRETRAINED_MODEL_ARCHIVE_LIST,
        MusicgenForCausalLM,
        MusicgenForConditionalGeneration,
        MusicgenModel,
        MusicgenPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase__			:  Dict					     =     _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




