


'''simple docstring'''






class 						a__							:





							'''simple docstring'''






							def __init__(						self   ,       lowerCamelCase_  )			->				None:
														lowerCAmelCase__			  =      set_counts
														lowerCAmelCase__			  =      max(lowerCamelCase_  )
														lowerCAmelCase__			  =      len(lowerCamelCase_  )
														lowerCAmelCase__			  =      [1] * num_sets
														lowerCAmelCase__			  =      list(range(lowerCamelCase_  )  )







							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_   ,       lowerCamelCase_  )			->				bool:
														lowerCAmelCase__			  =      self.get_parent(lowerCamelCase_  )
														lowerCAmelCase__			  =      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]
																					lowerCAmelCase__			  =      0
																					lowerCAmelCase__			  =      dst_parent
																					if self.ranks[dst_parent] == self.ranks[src_parent]:
																												self.ranks[dst_parent] += 1
																					lowerCAmelCase__			  =      self.set_counts[dst_parent]
														else:
																					self.set_counts[src_parent] += self.set_counts[dst_parent]
																					lowerCAmelCase__			  =      0
																					lowerCAmelCase__			  =      src_parent
																					lowerCAmelCase__			  =      self.set_counts[src_parent]

														lowerCAmelCase__			  =      max(self.max_set   ,       lowerCamelCase_  )
														return True







							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_  )			->				int:
														if self.parents[disj_set] == disj_set:
																					return disj_set
														lowerCAmelCase__			  =      self.get_parent(self.parents[disj_set]  )
														return self.parents[disj_set]



'''simple docstring'''






from __future__ import annotations

from random import choice


def    _snake_case  (	A			)		->       int:
							return choice(A			)


def    _snake_case  (	A					,       A			)		->       int:
							lowerCAmelCase__			  =      random_pivot(A			)

							# partition based on pivot
							# linear time
							lowerCAmelCase__			  =      [e for e in lst if e < pivot]
							lowerCAmelCase__			  =      [e for e in lst if e > pivot]

							# if we get lucky, pivot might be the element we want.
							# we can easily see this:
							# small (elements smaller than k)
							# + pivot (kth element)
							# + big (elements larger than k)
							if len(A			) == k - 1:
														return pivot
							# pivot is in elements bigger than k
							elif len(A			) < k - 1:
														return kth_number(A					,       k - len(A			) - 1			)
							# pivot is in elements smaller than k
							else:
														return kth_number(A					,       A			)


if __name__ == "__main__":
		import doctest

		doctest.testmod()