



'''simple docstring'''





from math import factorial

__a          =		{str(digit): factorial(digit) for digit in range(10)}





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





def 						__snake_case(				_lowerCAmelCase = 60     ,   _lowerCAmelCase = 1_000_000		)		-> int:

      if not isinstance(_lowerCAmelCase     ,   _lowerCAmelCase		) or not isinstance(_lowerCAmelCase     ,   _lowerCAmelCase		):
            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__  :    List[str]    						=      0
      # the cached sizes of the previous chains
      snake_case__  :    dict[int, int]    						=      {}

      for start_chain_element in range(1     ,   _lowerCAmelCase		):
            # The temporary set will contain the elements of the chain
            snake_case__  :    List[Any]    						=      set()
            snake_case__  :    List[Any]    						=      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__  :    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(_lowerCAmelCase		)
                  chain_set_length += 1
                  snake_case__  :    int    						=      digit_factorial_sum(_lowerCAmelCase		)

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

            snake_case__  :    int    						=      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'''






from __future__ import annotations


def  snake_case_     (					_lowerCAmelCase  :						list[int | float]   ,      _lowerCAmelCase  :						int   ,      _lowerCAmelCase  :						int  )      ->   int | float:
							if len(_lowerCAmelCase  ) == 0:
														raise ValueError('''find_max() arg is an empty sequence'''  )
							if (
							    left >= len(_lowerCAmelCase  )
							    or left < -len(_lowerCAmelCase  )
							    or right >= len(_lowerCAmelCase  )
							    or right < -len(_lowerCAmelCase  )
							):
														raise IndexError('''list index out of range'''  )
							if left == right:
														return nums[left]
							UpperCAmelCase :       List[Any] 							=		(left + right) >> 1  # the middle
							UpperCAmelCase :       Optional[Any] 							=		find_max(_lowerCAmelCase   ,      _lowerCAmelCase   ,      _lowerCAmelCase  )  # find max in range[left, mid]
							UpperCAmelCase :       Dict 							=		find_max(_lowerCAmelCase   ,      mid + 1   ,      _lowerCAmelCase  )  # find max in range[mid + 1, right]

							return left_max if left_max >= right_max else right_max


if __name__ == "__main__":
						import doctest

						doctest.testmod(verbose=True)





