"""simple docstring"""





from math import factorial

_UpperCamelCase  :		dict[str, int]           =       {str(digit): factorial(digit) for digit in range(10)}





def 							a_	( _lowerCAmelCase    :					Optional[int]	):





       '''simple docstring'''

       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 							a_	( _lowerCAmelCase    :					Dict = 60  ,					_lowerCAmelCase    :					Optional[Any] = 100_0000	):





       '''simple docstring'''

       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
       lowercase__     :						Optional[Any]         =      0
       # the cached sizes of the previous chains
       lowercase__     :						Optional[Any]         =      {}

       for start_chain_element in range(1  ,					UpperCAmelCase_	):
              # The temporary set will contain the elements of the chain
              lowercase__     :						int         =      set()
              lowercase__     :						int         =      0

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

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

              lowercase__     :						Any         =      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()}''')








'''simple docstring'''




import enum
import shutil
import sys


a__      ,       a__					:			Any          =     shutil.get_terminal_size()

a__					:			Optional[int]          =     {'''UP''': '''A''', '''DOWN''': '''B''', '''RIGHT''': '''C''', '''LEFT''': '''D'''}






class 				__snake_case     (					enum.Enum							):
	__lowerCAmelCase       						=  0
	__lowerCAmelCase       						=  1





def 						__lowerCamelCase			(	UpperCAmelCase_					,				UpperCAmelCase_=""							)   ->Optional[Any]:
	sys.stdout.write(str(UpperCAmelCase_							) + end							)
	sys.stdout.flush()




def 						__lowerCamelCase			(	UpperCAmelCase_					,				UpperCAmelCase_					,				UpperCAmelCase_=""							)   ->List[str]:
	forceWrite(f'''\u001b[{color}m{content}\u001b[0m'''					,				UpperCAmelCase_							)




def 						__lowerCamelCase			(	)   ->Optional[Any]:
	forceWrite('\r'							)




def 						__lowerCamelCase			(	UpperCAmelCase_					,				UpperCAmelCase_							)   ->Any:
	forceWrite(f'''\033[{num_lines}{CURSOR_TO_CHAR[direction.upper()]}'''							)




def 						__lowerCamelCase			(	)   ->str:
	forceWrite(' ' * TERMINAL_WIDTH							)
	reset_cursor()







def 						__lowerCamelCase			(	)   ->Tuple:
	reset_cursor()
	forceWrite('-' * TERMINAL_WIDTH							)



