



class       UpperCAmelCase__:

   '''simple docstring'''




   def __init__(						self  :			Tuple			,				lowerCAmelCase  :			int)	->				None:




         """simple docstring"""

         lowercase__     =  set_counts
         lowercase__     =  max(__A)
         lowercase__     =  len(__A)
         lowercase__     =  [1] * num_sets
         lowercase__     =  list(range(__A))


   def 			UpperCAmelCase		(						self  :			Optional[Any]			,				lowerCAmelCase  :			Any			,				lowerCAmelCase  :			Dict)	->				bool:




         """simple docstring"""

         lowercase__     =  self.get_parent(__A)
         lowercase__     =  self.get_parent(__A)

         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]
               lowercase__     =  0
               lowercase__     =  dst_parent
               if self.ranks[dst_parent] == self.ranks[src_parent]:
                     self.ranks[dst_parent] += 1
               lowercase__     =  self.set_counts[dst_parent]
         else:
               self.set_counts[src_parent] += self.set_counts[dst_parent]
               lowercase__     =  0
               lowercase__     =  src_parent
               lowercase__     =  self.set_counts[src_parent]

         lowercase__     =  max(self.max_set			,				__A)
         return True



   def 			UpperCAmelCase		(						self  :			Any			,				lowerCAmelCase  :			Tuple)	->				int:




         """simple docstring"""

         if self.parents[disj_set] == disj_set:
               return disj_set
         lowercase__     =  self.get_parent(self.parents[disj_set])
         return self.parents[disj_set]





from __future__ import annotations

def   _lowerCAmelCase   (						A__						,  A__	):
      if b == 0:
            return (1, 0)
      ((lowercase__),	(lowercase__))     =  extended_euclid(A__						,  a % b	)
      lowercase__     =  a // b
      return (y, x - k * y)

def   _lowerCAmelCase   (						A__						,  A__						,  A__						,  A__	):
      ((lowercase__),	(lowercase__))     =  extended_euclid(A__						,  A__	)
      lowercase__     =  na * na
      lowercase__     =  ra * x * na + ra * y * na
      return (n % m + m) % m

def   _lowerCAmelCase   (						A__						,  A__	):
      ((lowercase__),	(lowercase__))     =  extended_euclid(A__						,  A__	)
      if b < 0:
            lowercase__     =  (b % n + n) % n
      return b

def   _lowerCAmelCase   (						A__						,  A__						,  A__						,  A__	):
      lowercase__,	lowercase__     =  invert_modulo(A__						,  A__	), invert_modulo(A__						,  A__	)
      lowercase__     =  na * na
      lowercase__     =  ra * x * na + ra * y * na
      return (n % m + m) % m


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

       testmod(name="chinese_remainder_theorem", verbose=True)
       testmod(name="chinese_remainder_theorem2", verbose=True)
       testmod(name="invert_modulo", verbose=True)
       testmod(name="extended_euclid", verbose=True)
