



_lowercase:					str      =						{
    '0': 1,
    '1': 1,
    '2': 2,
    '3': 6,
    '4': 24,
    '5': 120,
    '6': 720,
    '7': 5040,
    '8': 40320,
    '9': 362880,
}

_lowercase:					List[str]      =						{145: 145}

_lowercase:					str      =						{
    145: 0,
    169: 3,
    36301: 3,
    1454: 3,
    871: 2,
    45361: 2,
    872: 2,
}






def        a( A			:       Dict			)						->			Any:
					"""simple docstring"""





					if n in CACHE_SUM_DIGIT_FACTORIALS:
										return CACHE_SUM_DIGIT_FACTORIALS[n]
					a   	=  sum(DIGIT_FACTORIALS[let] for let in str(lowercase__			)			)
					a   	=  ret
					return ret






def        a( A			:       List[Any]					,	A			:       Any = None			)						->			List[str]:
					"""simple docstring"""





					a   	=  previous or set()
					if n in CHAIN_LENGTH_CACHE:
										return CHAIN_LENGTH_CACHE[n]
					a   	=  sum_digit_factorials(lowercase__			)
					if next_number in previous:
										a   	=  0
										return 0
					else:
										previous.add(lowercase__			)
										a   	=  1 + chain_length(lowercase__					,	lowercase__			)
										a   	=  ret
										return ret






def        a( A			:       List[Any] = 60					,	A			:       List[Any] = 100_0000			)						->			Optional[int]:
					"""simple docstring"""





					return sum(1 for i in range(1					,	lowercase__			) if chain_length(lowercase__			) == num_terms			)


if __name__ == "__main__":
				print(F"""{solution() = }""")



"""simple docstring"""




import sys

sys.set_int_max_str_digits(0)  # type: ignore
def   __SCREAMING_SNAKE_CASE		(		lowercase__ ):
					"""simple docstring"""
					A     =   [0] * 11
					A     =   [0] * 11

					# mark last 9 numbers
					for _ in range(9 ):
										A     =   1
										A     =   number // 10
					# flag
					A     =   True

					# check last 9 numbers for pandigitality

					for x in range(9 ):
										if not check_last[x + 1]:
															A     =   False
					if not f:
										return f

					# mark first 9 numbers
					A     =   int(str(lowercase__ )[:9] )

					for _ in range(9 ):
										A     =   1
										A     =   number // 10

					# check first 9 numbers for pandigitality

					for x in range(9 ):
										if not check_front[x + 1]:
															A     =   False
					return f
def   __SCREAMING_SNAKE_CASE		(		lowercase__ ):
					"""simple docstring"""
					A     =   [0] * 11

					# mark last 9 numbers
					for _ in range(9 ):
										A     =   1
										A     =   number // 10
					# flag
					A     =   True

					# check last 9 numbers for pandigitality

					for x in range(9 ):
										if not check_last[x + 1]:
															A     =   False
					return f
def   __SCREAMING_SNAKE_CASE		(		):
					"""simple docstring"""
					A     =   1
					A     =   1
					A     =   2
					# temporary Fibonacci numbers

					A     =   1
					A     =   1
					A     =   2
					# temporary Fibonacci numbers mod 1e9

					# mod m=1e9, done for fast optimisation
					A     =   [0] * 1_000_000
					A     =   1_000_000_000

					for x in range(1_000_000 ):
										A     =   (aa + ba) % m
										A     =   ba % m
										A     =   ca % m
										if checka(lowercase__ ):
															A     =   1

					for x in range(1_000_000 ):
										A     =   a + b
										A     =   b
										A     =   c
										# perform check only if in tocheck
										if tocheck[x + 3] and check(lowercase__ ):
															return x + 3  # first 2 already done
					return -1


if __name__ == "__main__":
	print(f"""{solution() = }""")





