
"""simple docstring"""






UpperCamelCase_						   =   {
    '0': 1,
    '1': 1,
    '2': 2,
    '3': 6,
    '4': 24,
    '5': 120,
    '6': 720,
    '7': 5040,
    '8': 40320,
    '9': 362880,
}

UpperCamelCase_						   =   {145: 145}

UpperCamelCase_						   =   {
    145: 0,
    169: 3,
    36301: 3,
    1454: 3,
    871: 2,
    45361: 2,
    872: 2,
}
def    UpperCamelCase						(					UpperCAmelCase     )						->int:

   """simple docstring"""



   if n in CACHE_SUM_DIGIT_FACTORIALS:
      return CACHE_SUM_DIGIT_FACTORIALS[n]
   a_						   =     sum(DIGIT_FACTORIALS[let] for let in str(UpperCAmelCase     )     )
   a_						   =     ret
   return ret
def    UpperCamelCase						(					UpperCAmelCase ,   UpperCAmelCase = None     )						->int:

   """simple docstring"""



   a_						   =     previous or set()
   if n in CHAIN_LENGTH_CACHE:
      return CHAIN_LENGTH_CACHE[n]
   a_						   =     sum_digit_factorials(UpperCAmelCase     )
   if next_number in previous:
      a_						   =     0
      return 0
   else:
      previous.add(UpperCAmelCase     )
      a_						   =     1 + chain_length(UpperCAmelCase ,   UpperCAmelCase     )
      a_						   =     ret
      return ret
def    UpperCamelCase						(					UpperCAmelCase = 60 ,   UpperCAmelCase = 1_000_000     )						->int:

   """simple docstring"""



   return sum(1 for i in range(1 ,   UpperCAmelCase     ) if chain_length(UpperCAmelCase     ) == num_terms     )


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

"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


UpperCamelCase_						   =   {
    'configuration_sam': [
        'SAM_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'SamConfig',
        'SamMaskDecoderConfig',
        'SamPromptEncoderConfig',
        'SamVisionConfig',
    ],
    'processing_sam': ['SamProcessor'],
}


try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase_						   =   [
          'SAM_PRETRAINED_MODEL_ARCHIVE_LIST',
          'SamModel',
          'SamPreTrainedModel',
      ]
try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase_						   =   [
          'TF_SAM_PRETRAINED_MODEL_ARCHIVE_LIST',
          'TFSamModel',
          'TFSamPreTrainedModel',
      ]
try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase_						   =   ['SamImageProcessor']


if TYPE_CHECKING:
      from .configuration_sam import (
          SAM_PRETRAINED_CONFIG_ARCHIVE_MAP,
          SamConfig,
          SamMaskDecoderConfig,
          SamPromptEncoderConfig,
          SamVisionConfig,
      )
      from .processing_sam import SamProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_sam import SAM_PRETRAINED_MODEL_ARCHIVE_LIST, SamModel, SamPreTrainedModel

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_sam import TF_SAM_PRETRAINED_MODEL_ARCHIVE_LIST, TFSamModel, TFSamPreTrainedModel

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .image_processing_sam import SamImageProcessor

else:
      import sys

      UpperCamelCase_						   =   _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)