
'''simple docstring'''

from __future__ import annotations

from typing import Generic, TypeVar

__snake_case:  List[str]   							=			TypeVar("T")


class  _UpperCAmelCase ( Generic[T]    ):

     """simple docstring"""

     def __init__(      self							,		lowerCAmelCase_ ):

       '''simple docstring'''

       a_      :	List[str]      =							data
       a_      :	Optional[Any]      =							self
       a_      :	str      =							0







class  _UpperCAmelCase ( Generic[T]    ):

     """simple docstring"""

     def __init__(      self ):

       '''simple docstring'''

       a_      :	int      =							{}


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_ ):

       '''simple docstring'''

       a_      :	Any      =							DisjointSetTreeNode(lowerCAmelCase_ )


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_ ):

       '''simple docstring'''

       a_      :	Optional[Any]      =							self.map[data]
       if elem_ref != elem_ref.parent:
         a_      :	int      =							self.find_set(elem_ref.parent.data )
       return elem_ref.parent


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_ ):

       '''simple docstring'''

       if nodea.rank > nodea.rank:
         a_      :	List[Any]      =							nodea
       else:
         a_      :	Dict      =							nodea
         if nodea.rank == nodea.rank:
           nodea.rank += 1






     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_ ):

       '''simple docstring'''

       self.link(self.find_set(lowerCAmelCase_ )							,		self.find_set(lowerCAmelCase_ ) )







class  _UpperCAmelCase ( Generic[T]    ):

     """simple docstring"""

     def __init__(      self ):

       '''simple docstring'''

       a_      :	List[str]      =							{}


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_ ):

       '''simple docstring'''

       if node not in self.connections:
         a_      :	Dict      =							{}


     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ ):

       '''simple docstring'''

       self.add_node(lowerCAmelCase_ )
       self.add_node(lowerCAmelCase_ )
       a_      :	str      =							weight
       a_      :	int      =							weight






     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

       a_      :	Dict      =							[]
       a_      :	List[Any]      =							set()
       for start in self.connections:
         for end in self.connections[start]:
           if (start, end) not in seen:
             seen.add((end, start) )
             edges.append((start, end, self.connections[start][end]) )
       edges.sort(key=lambda lowerCAmelCase_ : x[2] )

       # creating the disjoint set
       a_      :	List[str]      =							DisjointSetTree[T]()
       for node in self.connections:
         disjoint_set.make_set(lowerCAmelCase_ )

       # MST generation
       a_      :	List[Any]      =							0
       a_      :	Dict      =							0
       a_      :	List[str]      =							GraphUndirectedWeighted[T]()
       while num_edges < len(self.connections ) - 1:
         a_      , a_      , a_      :	Optional[Any]      =							edges[index]
         index += 1
         a_      :	Tuple      =							disjoint_set.find_set(lowerCAmelCase_ )
         a_      :	List[Any]      =							disjoint_set.find_set(lowerCAmelCase_ )
         if parent_u != parent_v:
           num_edges += 1
           graph.add_edge(lowerCAmelCase_							,		lowerCAmelCase_							,		lowerCAmelCase_ )
           disjoint_set.union(lowerCAmelCase_							,		lowerCAmelCase_ )
       return graph




'''simple docstring'''

from math import factorial

__snake_case:  List[Any]								=			{str(d): factorial(d) for d in range(10)}






def 	_snake_case						(      A_       :    int   ):
  """simple docstring"""







  return sum(DIGIT_FACTORIAL[d] for d in str(A_   )   )






def 	_snake_case						(      ):
  """simple docstring"""







  a_      :	Union[str, Any]      =							7 * factorial(9   ) + 1
  return sum(i for i in range(3     ,		A_   ) if sum_of_digit_factorial(A_   ) == i   )


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


