


'''simple docstring'''

from __future__ import annotations



def 							UpperCamelCase__			(			a__			,      a__      ):


						'''simple docstring'''






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



def 							UpperCamelCase__			(			a__			,      a__			,      a__			,      a__      ):


						'''simple docstring'''






						((_lowerCAmelCase)						,				(_lowerCAmelCase))										=extended_euclid(lowerCamelCase_			,      lowerCamelCase_      )
						_lowerCAmelCase										=na * na
						_lowerCAmelCase										=ra * x * na + ra * y * na
						return (n % m + m) % m



def 							UpperCamelCase__			(			a__			,      a__      ):


						'''simple docstring'''






						((_lowerCAmelCase)						,				(_lowerCAmelCase))										=extended_euclid(lowerCamelCase_			,      lowerCamelCase_      )
						if b < 0:
												_lowerCAmelCase										=(b % n + n) % n
						return b



def 							UpperCamelCase__			(			a__			,      a__			,      a__			,      a__      ):


						'''simple docstring'''






						_lowerCAmelCase						,				_lowerCAmelCase										=invert_modulo(lowerCamelCase_			,      lowerCamelCase_      ), invert_modulo(lowerCamelCase_			,      lowerCamelCase_      )
						_lowerCAmelCase										=na * na
						_lowerCAmelCase										=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)






'''simple docstring'''

def 							UpperCamelCase__			(			a__      ):


						'''simple docstring'''






						_lowerCAmelCase										=set()
						# To detect a back edge, keep track of vertices currently in the recursion stack
						_lowerCAmelCase										=set()
						return any(
						    node not in visited and depth_first_search(a__			,      a__			,      a__			,      a__      )
						    for node in graph      )



def 							UpperCamelCase__			(			a__			,      a__			,      a__			,      a__      ):


						'''simple docstring'''






						visited.add(a__      )
						rec_stk.add(a__      )

						for node in graph[vertex]:
												if node not in visited:
																		if depth_first_search(a__			,      a__			,      a__			,      a__      ):
																								return True
												elif node in rec_stk:
																		return True

    # The node needs to be removed from recursion stack before function ends
						rec_stk.remove(a__      )
						return False


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

							testmod()





