"""simple docstring"""






lowerCAmelCase__    :    List[str]			=      {
    '0': 1,
    '1': 1,
    '2': 2,
    '3': 6,
    '4': 24,
    '5': 120,
    '6': 720,
    '7': 5_040,
    '8': 40_320,
    '9': 362_880,
}

lowerCAmelCase__    :    Union[str, Any]			=      {145: 145}

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



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



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



def     a_		(   lowerCamelCase = 6_0   ,     lowerCamelCase = 1_0_0_0_0_0_0			):
				return sum(1 for i in range(1   ,     lowerCamelCase			) if chain_length(lowerCamelCase			) == num_terms			)


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




"""simple docstring"""






import os
import unittest

import pytest
from parameterized import parameterized

from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device


# skipping in unittest tests

lowerCAmelCase__    :    Union[str, Any]			=      [(1,)]



def     a_		(   ):
				UpperCAmelCase__			 =				bool(os.getenv('RUN_SLOW'   ,     0			)			)
				if run_slow:
								assert True
				else:
								assert False, "should have been skipped"



def     a_		(   ):
				UpperCAmelCase__			 =				bool(os.getenv('RUN_SLOW'   ,     0			)			)
				if run_slow and torch_device == "cuda":
								assert True
				else:
								assert False, "should have been skipped"
@require_torch
class 							snake_case			(					unittest.TestCase							):




					"""simple docstring"""

					@slow
					@require_torch_gpu
					def 						__lowerCAmelCase		(							self  :      Optional[Any]     ):
									check_slow_torch_cuda()







					@require_torch_gpu
					@slow
					def 						__lowerCAmelCase		(							self  :      Any     ):
									check_slow_torch_cuda()







					@parameterized.expand(lowerCamelCase__     )
					@slow
					def 						__lowerCAmelCase		(							self  :      Union[str, Any]       ,lowerCamelCase__  :      str=None     ):
									check_slow()






@slow
@require_torch_gpu
def     a_		(   ):
				check_slow_torch_cuda()



@require_torch_gpu
@slow
def     a_		(   ):
				check_slow_torch_cuda()



@slow
@pytest.mark.parametrize('param'   ,     [1]			)
def     a_		(   lowerCamelCase			):
				check_slow()







@pytest.mark.parametrize('param'   ,     [1]			)
@slow
def     a_		(   lowerCamelCase			):
				check_slow()



