


from math import factorial

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




def     __SCREAMING_SNAKE_CASE							(       lowercase_      )		->     int:




						'''simple docstring'''







						if not isinstance(lowercase_      ,       lowercase_      ):
												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(lowercase_      )      )




def     __SCREAMING_SNAKE_CASE							(       lowercase_ = 60      ,       lowercase_ = 1000000      )		->     int:




						'''simple docstring'''







						if not isinstance(lowercase_      ,       lowercase_      ) or not isinstance(lowercase_      ,       lowercase_      ):
												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
						__UpperCAmelCase			:							Dict	    =	0
						# the cached sizes of the previous chains
						__UpperCAmelCase			:							dict[int, int]	    =	{}

						for start_chain_element in range(1      ,       lowercase_      ):
												# The temporary set will contain the elements of the chain
												__UpperCAmelCase			:							Tuple	    =	set()
												__UpperCAmelCase			:							str	    =	0

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

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

												__UpperCAmelCase			:							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()}')





def     __SCREAMING_SNAKE_CASE							(       )		->     Optional[int]:




						'''simple docstring'''







						__UpperCAmelCase			:							str	    =	[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

						__UpperCAmelCase			:							Union[str, Any]	    =	6
						__UpperCAmelCase			:							Optional[Any]	    =	1
						__UpperCAmelCase			:							Tuple	    =	1901

						__UpperCAmelCase			:							Any	    =	0

						while year < 2001:
												day += 7

												if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
																		if day > days_per_month[month - 1] and month != 2:
																								month += 1
																								__UpperCAmelCase			:							Optional[int]	    =	day - days_per_month[month - 2]
																		elif day > 29 and month == 2:
																								month += 1
																								__UpperCAmelCase			:							Optional[Any]	    =	day - 29
												else:
																		if day > days_per_month[month - 1]:
																								month += 1
																								__UpperCAmelCase			:							Optional[Any]	    =	day - days_per_month[month - 2]

												if month > 12:
																		year += 1
																		__UpperCAmelCase			:							int	    =	1

												if year < 2001 and day == 1:
																		sundays += 1
						return sundays


if __name__ == "__main__":
				print(solution())

