




'''simple docstring'''






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

_lowerCAmelCase       =   {145: 145}

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

def      __lowerCAmelCase   (       snake_case__		):
			if n in CACHE_SUM_DIGIT_FACTORIALS:
						return CACHE_SUM_DIGIT_FACTORIALS[n]
			__UpperCamelCase :     Optional[int]										=  sum(DIGIT_FACTORIALS[let] for let in str(snake_case__		)		)
			__UpperCamelCase :     Dict										=  ret
			return ret

def      __lowerCAmelCase   (       snake_case__   , snake_case__ = None		):
			__UpperCamelCase :     Dict										=  previous or set()
			if n in CHAIN_LENGTH_CACHE:
						return CHAIN_LENGTH_CACHE[n]
			__UpperCamelCase :     str										=  sum_digit_factorials(snake_case__		)
			if next_number in previous:
						__UpperCamelCase :     Union[str, Any]										=  0
						return 0
			else:
						previous.add(snake_case__		)
						__UpperCamelCase :     Union[str, Any]										=  1 + chain_length(snake_case__   , snake_case__		)
						__UpperCamelCase :     Optional[int]										=  ret
						return ret

def      __lowerCAmelCase   (       snake_case__ = 60   , snake_case__ = 1_000_000		):
			return sum(1 for i in range(1   , snake_case__		) if chain_length(snake_case__		) == num_terms		)


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









'''simple docstring'''






def      __lowerCAmelCase   (       snake_case__		):
			__UpperCamelCase :     int										=  word.upper()
			__UpperCamelCase :     List[str]										=  0
			__UpperCamelCase :     int										=  {}
			__UpperCamelCase :     Tuple										=  []

			for letter in word:
						if letter not in letter_nums:
									__UpperCamelCase :     Tuple										=  str(snake_case__		)
									next_num += 1
						word_pattern.append(letter_nums[letter]		)
			return ".".join(snake_case__		)


if __name__ == "__main__":
				import pprint
				import time

				_lowerCAmelCase       =   time.time()
				with open('''dictionary.txt''') as in_file:
								_lowerCAmelCase       =   in_file.read().splitlines()

				_lowerCAmelCase       =   {}
				for word in word_list:
								_lowerCAmelCase       =   get_word_pattern(word)
								if pattern in all_patterns:
												all_patterns[pattern].append(word)
								else:
												_lowerCAmelCase       =   [word]

				with open('''word_patterns.txt''', '''w''') as out_file:
								out_file.write(pprint.pformat(all_patterns))

				_lowerCAmelCase       =   round(time.time() - start_time, 2)
				print(f'Done!  {len(all_patterns):,} word patterns found in {total_time} seconds.')
				# Done!  9,581 word patterns found in 0.58 seconds.



