






from math import factorial

a__       =     {str(digit): factorial(digit) for digit in range(1_0)}

def _UpperCAmelCase   (	a						:	int ):
       if not isinstance(a  ,					a ):
              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(a ) )

def _UpperCAmelCase   (	a						:	int = 60  ,					a						:	int = 100_0000 ):

       if not isinstance(a  ,					a ) or not isinstance(a  ,					a ):
              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
       snake_case__	  =       0
       # the cached sizes of the previous chains
       snake_case__	  =       {}

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

              # Stop computing the chain when you find a cached size, a repeating item or the
              # length is greater then the desired one.
              snake_case__	  =       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(a )
                     chain_set_length += 1
                     snake_case__	  =       digit_factorial_sum(a )

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

              snake_case__	  =       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()}''')








from __future__ import annotations


class    _lowerCAmelCase			:



				"""simple docstring"""



				def __init__(      self    :    Optional[int]			,		UpperCamelCase__    :    int):






											'''simple docstring'''







											snake_case__	  =       data
											snake_case__	  =       None
											snake_case__	  =       None


def _UpperCAmelCase   (	a						:	Node | None ):  # In Order traversal of the tree
							if tree:
														display(tree.left )
														print(tree.data )
														display(tree.right )

def _UpperCAmelCase   (	a						:	Node | None ):
							return 1 + max(depth_of_tree(tree.left )  ,					depth_of_tree(tree.right ) ) if tree else 0

def _UpperCAmelCase   (	a						:	Node ):
							if not tree:
														return True
							if tree.left and tree.right:
														return is_full_binary_tree(tree.left ) and is_full_binary_tree(tree.right )
							else:
														return not tree.left and not tree.right

def _UpperCAmelCase   (	):  # Main function for testing.
							snake_case__	  =       Node(1 )
							snake_case__	  =       Node(2 )
							snake_case__	  =       Node(3 )
							snake_case__	  =       Node(4 )
							snake_case__	  =       Node(5 )
							snake_case__	  =       Node(6 )
							snake_case__	  =       Node(7 )
							snake_case__	  =       Node(8 )
							snake_case__	  =       Node(9 )

							print(is_full_binary_tree(a ) )
							print(depth_of_tree(a ) )
							print("""Tree is: """ )
							display(a )


if __name__ == "__main__":
	main()
