

from __future__ import annotations

from typing import Any





class      _lowerCAmelCase :




				def __init__( self    ,    _UpperCamelCase    ,    _UpperCamelCase					)    ->				None:  # noqa: A002
							lowerCAmelCase_      =     item
							lowerCAmelCase_      =     next





class      _lowerCAmelCase :




				def __init__( self					)    ->				None:
							lowerCAmelCase_      =     None
							lowerCAmelCase_      =     0




				def 					__a						( self    ,    _UpperCamelCase					)    ->				None:
							lowerCAmelCase_      =     Node(_UpperCamelCase    ,    self.head					)
							self.size += 1




				def 					__a						( self					)    ->				Any:
							# Switched 'self.is_empty()' to 'self.head is None'
							# because mypy was considering the possibility that 'self.head'
							# can be None in below else part and giving error
							if self.head is None:
										return None
							else:
										lowerCAmelCase_      =     self.head.item
										lowerCAmelCase_      =     self.head.next
										self.size -= 1
										return item




				def 					__a						( self					)    ->				bool:
							return self.head is None




				def __str__( self					)    ->				str:
							if self.is_empty():
										return ""
							else:
										lowerCAmelCase_      =     self.head
										lowerCAmelCase_      =     ""
										lowerCAmelCase_      =     []
										while iterate:
													item_list.append(str(iterate.item					)					)
													lowerCAmelCase_      =     iterate.next

										lowerCAmelCase_      =     " --> ".join(_UpperCamelCase					)

										return item_str




				def __len__( self					)    ->				int:
							return self.size





from __future__ import annotations






def        lowerCamelCase__    (    __lowerCAmelCase  :  int   ,							__lowerCAmelCase  :  int   ,							__lowerCAmelCase  :  int    ):




			"""simple docstring"""


			assert n > 1 and a > 0 and greatest_common_divisor(__lowerCAmelCase   ,							__lowerCAmelCase    ) == 1
			((lowerCAmelCase_)     ,  (lowerCAmelCase_)     ,  (lowerCAmelCase_))      =     extended_gcd(__lowerCAmelCase   ,							__lowerCAmelCase    )  # Implemented below
			lowerCAmelCase_      =     (b * s) % n
			return x






def        lowerCamelCase__    (    __lowerCAmelCase  :  int   ,							__lowerCAmelCase  :  int    ):




			"""simple docstring"""


			((lowerCAmelCase_)     ,  (lowerCAmelCase_))      =     extended_euclid(__lowerCAmelCase   ,							__lowerCAmelCase    )  # Implemented below
			if b < 0:
						lowerCAmelCase_      =     (b % n + n) % n
			return b






def        lowerCamelCase__    (    __lowerCAmelCase  :  int   ,							__lowerCAmelCase  :  int   ,							__lowerCAmelCase  :  int    ):




			"""simple docstring"""


			lowerCAmelCase_      =     invert_modulo(__lowerCAmelCase   ,							__lowerCAmelCase    )
			lowerCAmelCase_      =     (b * s) % n
			return x






def        lowerCamelCase__    (    __lowerCAmelCase  :  int   ,							__lowerCAmelCase  :  int    ):




			"""simple docstring"""


			assert a >= 0 and b >= 0

			if b == 0:
						lowerCAmelCase_     ,  lowerCAmelCase_     ,  lowerCAmelCase_      =     a, 1, 0
			else:
						((lowerCAmelCase_)     ,  (lowerCAmelCase_)     ,  (lowerCAmelCase_))      =     extended_gcd(__lowerCAmelCase   ,							a % b    )
						lowerCAmelCase_      =     q
						lowerCAmelCase_      =     p - q * (a // b)

			assert a % d == 0 and b % d == 0
			assert d == a * x + b * y

			return (d, x, y)






def        lowerCamelCase__    (    __lowerCAmelCase  :  int   ,							__lowerCAmelCase  :  int    ):




			"""simple docstring"""


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






def        lowerCamelCase__    (    __lowerCAmelCase  :  int   ,							__lowerCAmelCase  :  int    ):




			"""simple docstring"""


			if a < b:
						lowerCAmelCase_     ,  lowerCAmelCase_      =     b, a

			while a % b != 0:
						lowerCAmelCase_     ,  lowerCAmelCase_      =     b, a % b

			return b


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

			testmod(name="modular_division", verbose=True)
			testmod(name="modular_division2", verbose=True)
			testmod(name="invert_modulo", verbose=True)
			testmod(name="extended_gcd", verbose=True)
			testmod(name="extended_euclid", verbose=True)
			testmod(name="greatest_common_divisor", verbose=True)



