

from math import factorial

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


def     __SCREAMING_SNAKE_CASE   (SCREAMING_SNAKE_CASE__			):
						if not isinstance(SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__			):
												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(SCREAMING_SNAKE_CASE__			)			)


def     __SCREAMING_SNAKE_CASE   (SCREAMING_SNAKE_CASE__ = 60    ,						SCREAMING_SNAKE_CASE__ = 1000000			):

						if not isinstance(SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__			) or not isinstance(SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__			):
												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    ,						SCREAMING_SNAKE_CASE__			):
												# 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(SCREAMING_SNAKE_CASE__			)
																		chain_set_length += 1
																		snake_case_  =      digit_factorial_sum(SCREAMING_SNAKE_CASE__			)

												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()}""")




'''simple docstring'''





import functools

def 			a_	(				_lowerCAmelCase			,_lowerCAmelCase			) -> int:

  # Validation
  if not isinstance(_lowerCAmelCase			,_lowerCAmelCase			) or not all(isinstance(_lowerCAmelCase			,_lowerCAmelCase			) for day in days			):
    raise ValueError('The parameter days should be a list of integers'			)

  if len(_lowerCAmelCase			) != 3 or not all(isinstance(_lowerCAmelCase			,_lowerCAmelCase			) for cost in costs			):
    raise ValueError('The parameter costs should be a list of three integers'			)

  if len(_lowerCAmelCase			) == 0:
    return 0

  if min(_lowerCAmelCase			) <= 0:
    raise ValueError('All days elements should be greater than 0'			)

  if max(_lowerCAmelCase			) >= 366:
    raise ValueError('All days elements should be less than 366'			)

  __lowerCamelCase			:			int       			=					set(_lowerCAmelCase			)

  @functools.cache
  def dynamic_programming(_lowerCAmelCase			) -> int:
    if index > 365:
      return 0

    if index not in days_set:
      return dynamic_programming(index + 1			)

    return min(
        costs[0] + dynamic_programming(index + 1			)			,costs[1] + dynamic_programming(index + 7			)			,costs[2] + dynamic_programming(index + 30			)			,)

  return dynamic_programming(1			)


if __name__ == "__main__":
   import doctest

   doctest.testmod()






