






"""simple docstring"""





from __future__ import annotations

from collections.abc import Iterable, Iterator
from typing import Any, Generic, TypeVar

UpperCamelCase			=      TypeVar("""T""", bound=bool)







class 		_a       (						Generic[T]   ):





			'''simple docstring'''






			def __init__(   self			,				UpperCAmelCase_)	-> None:




										'''simple docstring'''




										lowercase__:    T        =      value
										lowercase__:    SkewNode[T] | None        =      None
										lowercase__:    SkewNode[T] | None        =      None





			@property
			def __lowercase    (   self)	-> T:




										'''simple docstring'''




										return self._value





			@staticmethod
			def __lowercase    (   UpperCAmelCase_			,				UpperCAmelCase_)	-> SkewNode[T] | None:




										'''simple docstring'''




										if not roota:
																	return roota

										if not roota:
																	return roota

										if roota.value > roota.value:
																	lowercase__:    List[str]        =      roota, roota

										lowercase__:    str        =      roota
										lowercase__:    List[str]        =      roota.right
										lowercase__:    str        =      roota.left
										lowercase__:    Dict        =      SkewNode.merge(UpperCAmelCase_			,				UpperCAmelCase_)

										return result







class 		_a       (						Generic[T]   ):





			'''simple docstring'''






			def __init__(   self			,				UpperCAmelCase_ = ())	-> None:




										'''simple docstring'''




										lowercase__:    SkewNode[T] | None        =      None
										if data:
																	for item in data:
																								self.insert(UpperCAmelCase_)





			def __bool__(   self)	-> bool:




										'''simple docstring'''




										return self._root is not None





			def __iter__(   self)	-> Iterator[T]:




										'''simple docstring'''




										lowercase__:    list[Any]        =      []
										while self:
																	result.append(self.pop())

										# Pushing items back to the heap not to clear it.
										for item in result:
																	self.insert(UpperCAmelCase_)

										return iter(UpperCAmelCase_)





			def __lowercase    (   self			,				UpperCAmelCase_)	-> None:




										'''simple docstring'''




										lowercase__:    str        =      SkewNode.merge(self._root			,				SkewNode(UpperCAmelCase_))





			def __lowercase    (   self)	-> T | None:




										'''simple docstring'''




										lowercase__:    List[Any]        =      self.top()
										lowercase__:    str        =      (
										    SkewNode.merge(self._root.left			,				self._root.right) if self._root else None
										)

										return result





			def __lowercase    (   self)	-> T:




										'''simple docstring'''




										if not self._root:
																	raise IndexError("Can't get top element for the empty heap.")
										return self._root.value





			def __lowercase    (   self)	-> None:




										'''simple docstring'''




										lowercase__:    List[Any]        =      None


if __name__ == "__main__":
		import doctest

		doctest.testmod()














"""simple docstring"""





UpperCamelCase			=      {
    """0""": 1,
    """1""": 1,
    """2""": 2,
    """3""": 6,
    """4""": 24,
    """5""": 1_20,
    """6""": 7_20,
    """7""": 50_40,
    """8""": 4_03_20,
    """9""": 36_28_80,
}

UpperCamelCase			=      {1_45: 1_45}

UpperCamelCase			=      {
    1_45: 0,
    1_69: 3,
    3_63_01: 3,
    14_54: 3,
    8_71: 2,
    4_53_61: 2,
    8_72: 2,
}






def     A(  snake_case_		):
       """simple docstring"""





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






def     A(  snake_case_						,       snake_case_ = None		):
       """simple docstring"""





       lowercase__:    Optional[int]        =      previous or set()
       if n in CHAIN_LENGTH_CACHE:
              return CHAIN_LENGTH_CACHE[n]
       lowercase__:    Tuple        =      sum_digit_factorials(snake_case_		)
       if next_number in previous:
              lowercase__:    List[Any]        =      0
              return 0
       else:
              previous.add(snake_case_		)
              lowercase__:    Optional[int]        =      1 + chain_length(snake_case_						,       snake_case_		)
              lowercase__:    Any        =      ret
              return ret






def     A(  snake_case_ = 60						,       snake_case_ = 1000000		):
       """simple docstring"""





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


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






