





"""simple docstring"""




from __future__ import annotations

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

UpperCamelCase_									=TypeVar("""T""")




class 			_a						(				Generic[T]    ):






				def __init__(			self		:   List[Any],			lowerCAmelCase__		:   T							)     ->				str:




										'''simple docstring'''



										_UpperCamelCase      : List[str]         =   data
										_UpperCamelCase      : Node[T] | None         =   None






				def __str__(			self		:   Tuple							)     ->				str:




										'''simple docstring'''



										return f"""{self.data}"""




class 			_a						(				Generic[T]    ):






				def __init__(			self		:   Optional[int]							)     ->				None:




										'''simple docstring'''



										_UpperCamelCase      : Node[T] | None         =   None






				def __iter__(			self		:   Union[str, Any]							)     ->				Iterator[T]:




										'''simple docstring'''



										_UpperCamelCase      : Dict         =   self.top
										while node:
																yield node.data
																_UpperCamelCase      : int         =   node.next






				def __str__(			self		:   int							)     ->				str:




										'''simple docstring'''



										return "->".join([str(lowerCAmelCase__							) for item in self]							)






				def __len__(			self		:   str							)     ->				int:




										'''simple docstring'''



										return len(tuple(iter(self							)							)							)






				def     snake_case     (			self		:   Optional[Any]							)     ->				bool:




										'''simple docstring'''



										return self.top is None






				def     snake_case     (			self		:   str,			lowerCAmelCase__		:   T							)     ->				None:




										'''simple docstring'''



										_UpperCamelCase      : Dict         =   Node(lowerCAmelCase__							)
										if not self.is_empty():
																_UpperCamelCase      : Tuple         =   self.top
										_UpperCamelCase      : Tuple         =   node






				def     snake_case     (			self		:   Any							)     ->				T:




										'''simple docstring'''



										if self.is_empty():
																raise IndexError('''pop from empty stack'''							)
										assert isinstance(self.top,			lowerCAmelCase__							)
										_UpperCamelCase      : str         =   self.top
										_UpperCamelCase      : Dict         =   self.top.next
										return pop_node.data






				def     snake_case     (			self		:   Optional[int]							)     ->				T:




										'''simple docstring'''



										if self.is_empty():
																raise IndexError('''peek from empty stack'''							)

										assert self.top is not None
										return self.top.data






				def     snake_case     (			self		:   List[str]							)     ->				None:




										'''simple docstring'''



										_UpperCamelCase      : Optional[Any]         =   None


if __name__ == "__main__":
						from doctest import testmod

						testmod()










"""simple docstring"""




class 			_a						:






				def __init__(			self		:   Optional[int],			lowerCAmelCase__		:   list							)     ->				None:




										'''simple docstring'''



										_UpperCamelCase      : Optional[int]         =   set_counts
										_UpperCamelCase      : Any         =   max(lowerCAmelCase__							)
										_UpperCamelCase      : int         =   len(lowerCAmelCase__							)
										_UpperCamelCase      : int         =   [1] * num_sets
										_UpperCamelCase      : List[Any]         =   list(range(lowerCAmelCase__							)							)






				def     snake_case     (			self		:   int,			lowerCAmelCase__		:   int,			lowerCAmelCase__		:   int							)     ->				bool:




										'''simple docstring'''



										_UpperCamelCase      : Optional[Any]         =   self.get_parent(lowerCAmelCase__							)
										_UpperCamelCase      : Any         =   self.get_parent(lowerCAmelCase__							)

										if src_parent == dst_parent:
																return False

										if self.ranks[dst_parent] >= self.ranks[src_parent]:
																self.set_counts[dst_parent] += self.set_counts[src_parent]
																_UpperCamelCase      : List[Any]         =   0
																_UpperCamelCase      : str         =   dst_parent
																if self.ranks[dst_parent] == self.ranks[src_parent]:
																						self.ranks[dst_parent] += 1
																_UpperCamelCase      : Union[str, Any]         =   self.set_counts[dst_parent]
										else:
																self.set_counts[src_parent] += self.set_counts[dst_parent]
																_UpperCamelCase      : Tuple         =   0
																_UpperCamelCase      : Optional[Any]         =   src_parent
																_UpperCamelCase      : int         =   self.set_counts[src_parent]

										_UpperCamelCase      : Optional[Any]         =   max(self.max_set,			lowerCAmelCase__							)
										return True






				def     snake_case     (			self		:   Optional[Any],			lowerCAmelCase__		:   int							)     ->				int:




										'''simple docstring'''



										if self.parents[disj_set] == disj_set:
																return disj_set
										_UpperCamelCase      : Union[str, Any]         =   self.get_parent(self.parents[disj_set]							)
										return self.parents[disj_set]



