"""simple docstring"""







UpperCamelCase_       :       Tuple							   =		{
    """0""": 1,
    """1""": 1,
    """2""": 2,
    """3""": 6,
    """4""": 24,
    """5""": 120,
    """6""": 720,
    """7""": 5040,
    """8""": 4_0320,
    """9""": 36_2880,
}

UpperCamelCase_       :       Dict							   =		{145: 145}

UpperCamelCase_       :       Optional[int]							   =		{
    145: 0,
    169: 3,
    3_6301: 3,
    1454: 3,
    871: 2,
    4_5361: 2,
    872: 2,
}


def   a__      (		UpperCAmelCase__       :			int			)->	int:

						'''simple docstring'''





						if n in CACHE_SUM_DIGIT_FACTORIALS:
												return CACHE_SUM_DIGIT_FACTORIALS[n]
						UpperCAmelCase__						=		sum(DIGIT_FACTORIALS[let] for let in str(UpperCAmelCase__			)			)
						UpperCAmelCase__						=		ret
						return ret


def   a__      (		UpperCAmelCase__       :			int		,			UpperCAmelCase__       :			set | None = None			)->	int:

						'''simple docstring'''





						UpperCAmelCase__						=		previous or set()
						if n in CHAIN_LENGTH_CACHE:
												return CHAIN_LENGTH_CACHE[n]
						UpperCAmelCase__						=		sum_digit_factorials(UpperCAmelCase__			)
						if next_number in previous:
												UpperCAmelCase__						=		0
												return 0
						else:
												previous.add(UpperCAmelCase__			)
												UpperCAmelCase__						=		1 + chain_length(UpperCAmelCase__		,			UpperCAmelCase__			)
												UpperCAmelCase__						=		ret
												return ret


def   a__      (		UpperCAmelCase__       :			int = 6_0		,			UpperCAmelCase__       :			int = 1_0_0_0_0_0_0			)->	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 ..utils import DummyObject, requires_backends


class 			_lowercase		(   metaclass=__lowerCamelCase  ):
				lowerCamelCase__						=       ['torch', 'transformers', 'invisible_watermark']

				def __init__(     self       :    Tuple       ,    *_lowercase       :    int       ,    **_lowercase       :    List[Any]     ):


										'''simple docstring'''
										requires_backends(self       ,    ["""torch""", """transformers""", """invisible_watermark"""]     )

				@classmethod
				def        A (     cls       :    Tuple       ,    *_lowercase       :    Dict       ,    **_lowercase       :    Union[str, Any]     ):


										'''simple docstring'''
										requires_backends(cls       ,    ["""torch""", """transformers""", """invisible_watermark"""]     )

				@classmethod
				def        A (     cls       :    Tuple       ,    *_lowercase       :    Tuple       ,    **_lowercase       :    Any     ):


										'''simple docstring'''
										requires_backends(cls       ,    ["""torch""", """transformers""", """invisible_watermark"""]     )


class 			_lowercase		(   metaclass=__lowerCamelCase  ):
				lowerCamelCase__						=       ['torch', 'transformers', 'invisible_watermark']

				def __init__(     self       :    Union[str, Any]       ,    *_lowercase       :    List[Any]       ,    **_lowercase       :    List[Any]     ):


										'''simple docstring'''
										requires_backends(self       ,    ["""torch""", """transformers""", """invisible_watermark"""]     )

				@classmethod
				def        A (     cls       :    List[str]       ,    *_lowercase       :    Any       ,    **_lowercase       :    Tuple     ):


										'''simple docstring'''
										requires_backends(cls       ,    ["""torch""", """transformers""", """invisible_watermark"""]     )

				@classmethod
				def        A (     cls       :    List[Any]       ,    *_lowercase       :    Optional[Any]       ,    **_lowercase       :    Union[str, Any]     ):


										'''simple docstring'''
										requires_backends(cls       ,    ["""torch""", """transformers""", """invisible_watermark"""]     )

