
"""simple docstring"""




from __future__ import annotations

from typing import Generic, TypeVar

UpperCAmelCase__   :					Optional[int]												=				TypeVar('T')



class 			lowerCAmelCase_		(Generic[T]						):


				"""simple docstring"""



				def __init__(self     , SCREAMING_SNAKE_CASE__					)      ->	None:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: Optional[int]     =     data
											SCREAMING_SNAKE_CASE__		: List[Any]     =     self
											SCREAMING_SNAKE_CASE__		: int     =     0






class 			lowerCAmelCase_		(Generic[T]						):


				"""simple docstring"""



				def __init__(self					)      ->	None:



											"""simple docstring"""




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



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__					)      ->	None:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: str     =     DisjointSetTreeNode(SCREAMING_SNAKE_CASE__					)



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__					)      ->	DisjointSetTreeNode[T]:



											"""simple docstring"""




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



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					)      ->	None:



											"""simple docstring"""




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



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					)      ->	None:



											"""simple docstring"""




											self.link(self.find_set(SCREAMING_SNAKE_CASE__					)     , self.find_set(SCREAMING_SNAKE_CASE__					)					)






class 			lowerCAmelCase_		(Generic[T]						):


				"""simple docstring"""



				def __init__(self					)      ->	None:



											"""simple docstring"""




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



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__					)      ->	None:



											"""simple docstring"""




											if node not in self.connections:
																		SCREAMING_SNAKE_CASE__		: Optional[Any]     =     {}



				def 			__magic_name__					(self     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__     , SCREAMING_SNAKE_CASE__					)      ->	None:



											"""simple docstring"""




											self.add_node(SCREAMING_SNAKE_CASE__					)
											self.add_node(SCREAMING_SNAKE_CASE__					)
											SCREAMING_SNAKE_CASE__		: List[str]     =     weight
											SCREAMING_SNAKE_CASE__		: str     =     weight



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



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__		: List[Any]     =     []
											SCREAMING_SNAKE_CASE__		: 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 SCREAMING_SNAKE_CASE__					: x[2]					)

											# creating the disjoint set
											SCREAMING_SNAKE_CASE__		: Optional[Any]     =     DisjointSetTree[T]()
											for node in self.connections:
																		disjoint_set.make_set(SCREAMING_SNAKE_CASE__					)

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






"""simple docstring"""




def lowercase_						(     _snake_case		):
							if divisor % 5 == 0 or divisor % 2 == 0:
														return 0
							SCREAMING_SNAKE_CASE__		: List[str]     =     1
							SCREAMING_SNAKE_CASE__		: List[Any]     =     1
							while repunit:
														SCREAMING_SNAKE_CASE__		: Dict     =     (10 * repunit + 1) % divisor
														repunit_index += 1
							return repunit_index

def lowercase_						(     _snake_case = 1_000_000		):
							SCREAMING_SNAKE_CASE__		: int     =     limit - 1
							if divisor % 2 == 0:
														divisor += 1
							while least_divisible_repunit(_snake_case		) <= limit:
														divisor += 2
							return divisor


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




