



'''simple docstring'''





from __future__ import annotations

from typing import Generic, TypeVar

__snake_case       :	Any            =TypeVar('T')



class  lowerCamelCase__    (							Generic[T]):




		'''simple docstring'''



		def __init__(self	,__lowerCamelCase				)  ->    None:

						"""simple docstring"""






						lowerCAmelCase__  :       int				=  data
						lowerCAmelCase__  :       str				=  self
						lowerCAmelCase__  :       str				=  0



class  lowerCamelCase__    (							Generic[T]):




		'''simple docstring'''



		def __init__(self				)  ->    None:

						"""simple docstring"""






						lowerCAmelCase__  :       dict[T, DisjointSetTreeNode[T]]				=  {}



		def 	lowerCAmelCase__   (self	,__lowerCamelCase				)  ->    None:

						"""simple docstring"""






						lowerCAmelCase__  :       List[Any]				=  DisjointSetTreeNode(lowerCamelCase__				)



		def 	lowerCAmelCase__   (self	,__lowerCamelCase				)  ->    DisjointSetTreeNode[T]:

						"""simple docstring"""






						lowerCAmelCase__  :       Any				=  self.map[data]
						if elem_ref != elem_ref.parent:
										lowerCAmelCase__  :       List[str]				=  self.find_set(elem_ref.parent.data				)
						return elem_ref.parent



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase				)  ->    None:

						"""simple docstring"""






						if nodea.rank > nodea.rank:
										lowerCAmelCase__  :       Dict				=  nodea
						else:
										lowerCAmelCase__  :       Union[str, Any]				=  nodea
										if nodea.rank == nodea.rank:
														nodea.rank += 1



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase				)  ->    None:

						"""simple docstring"""






						self.link(self.find_set(lowerCamelCase__				)	,self.find_set(lowerCamelCase__				)				)



class  lowerCamelCase__    (							Generic[T]):




		'''simple docstring'''



		def __init__(self				)  ->    None:

						"""simple docstring"""






						lowerCAmelCase__  :       dict[T, dict[T, int]]				=  {}



		def 	lowerCAmelCase__   (self	,__lowerCamelCase				)  ->    None:

						"""simple docstring"""






						if node not in self.connections:
										lowerCAmelCase__  :       List[str]				=  {}



		def 	lowerCAmelCase__   (self	,__lowerCamelCase	,__lowerCamelCase	,__lowerCamelCase				)  ->    None:

						"""simple docstring"""






						self.add_node(lowerCamelCase__				)
						self.add_node(lowerCamelCase__				)
						lowerCAmelCase__  :       Dict				=  weight
						lowerCAmelCase__  :       str				=  weight



		def 	lowerCAmelCase__   (self				)  ->    GraphUndirectedWeighted[T]:

						"""simple docstring"""






						lowerCAmelCase__  :       str				=  []
						lowerCAmelCase__  :       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
						lowerCAmelCase__  :       Tuple				=  DisjointSetTree[T]()
						for node in self.connections:
										disjoint_set.make_set(lowerCamelCase__				)

						# MST generation
						lowerCAmelCase__  :       List[Any]				=  0
						lowerCAmelCase__  :       Tuple				=  0
						lowerCAmelCase__  :       str				=  GraphUndirectedWeighted[T]()
						while num_edges < len(self.connections				) - 1:
										lowerCAmelCase__  :       Union[str, Any]				=  edges[index]
										index += 1
										lowerCAmelCase__  :       Union[str, Any]				=  disjoint_set.find_set(lowerCamelCase__				)
										lowerCAmelCase__  :       int				=  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






from __future__ import annotations






def 			lowerCAmelCase__	(					lowerCamelCase_	:	int):





				'''simple docstring'''

				lowerCAmelCase__  :       Optional[int]				=  str(lowerCamelCase_)
				return len(lowerCamelCase_) == 9 and set(lowerCamelCase_) == set('''123456789''')






def 			lowerCAmelCase__	(					):





				'''simple docstring'''

				for base_num in range(9999 ,4999 ,-1):
								lowerCAmelCase__  :       Union[str, Any]				=  100002 * base_num
								if is_9_pandigital(lowerCamelCase_):
												return candidate

				for base_num in range(333 ,99 ,-1):
								lowerCAmelCase__  :       Any				=  1002003 * base_num
								if is_9_pandigital(lowerCamelCase_):
												return candidate

				return None


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

