

'''simple docstring'''
_snake_case     						=						{
    '0': 1,
    '1': 1,
    '2': 2,
    '3': 6,
    '4': 24,
    '5': 120,
    '6': 720,
    '7': 5_040,
    '8': 40_320,
    '9': 362_880,
}

_snake_case     						=						{145: 145}

_snake_case     						=						{
    145: 0,
    169: 3,
    36_301: 3,
    1_454: 3,
    871: 2,
    45_361: 2,
    872: 2,
}







def       _A	(			snake_case  )    ->			int:
   if n in CACHE_SUM_DIGIT_FACTORIALS:
      return CACHE_SUM_DIGIT_FACTORIALS[n]
   _lowercase    :   Dict      =     sum(DIGIT_FACTORIALS[let] for let in str(snake_case  )  )
   _lowercase    :   Optional[Any]      =     ret
   return ret







def       _A	(			snake_case	,							snake_case = None  )    ->			int:
   _lowercase    :   Optional[int]      =     previous or set()
   if n in CHAIN_LENGTH_CACHE:
      return CHAIN_LENGTH_CACHE[n]
   _lowercase    :   Optional[Any]      =     sum_digit_factorials(snake_case  )
   if next_number in previous:
      _lowercase    :   Union[str, Any]      =     0
      return 0
   else:
      previous.add(snake_case  )
      _lowercase    :   List[str]      =     1 + chain_length(snake_case	,							snake_case  )
      _lowercase    :   List[Any]      =     ret
      return ret







def       _A	(			snake_case = 60	,							snake_case = 1_00_00_00  )    ->			int:
   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       _A	(			snake_case  )    ->			int:

   # validate:
   if not isinstance(snake_case	,							snake_case  ) or not all(
       isinstance(snake_case	,							snake_case  ) and item >= 0 for item in citations  ):
      raise ValueError("The citations should be a list of non negative integers."  )

   citations.sort()
   _lowercase    :   Tuple      =     len(snake_case  )

   for i in range(snake_case  ):
      if citations[len_citations - 1 - i] <= i:
         return i

   return len_citations


if __name__ == "__main__":
    import doctest

    doctest.testmod()






