

"""simple docstring"""


__A		     =    {hex(i)[2:]: i for i in range(16)}  # Use [:2] to strip off the leading '0x'






def 					a__					(					__SCREAMING_SNAKE_CASE				)			->			int:
		__lowerCAmelCase: str					   =    hex_string.strip().lower()
		if not hex_string:
				raise ValueError("Empty string was passed to the function"				)
		__lowerCAmelCase: str					   =    hex_string[0] == "-"
		if is_negative:
				__lowerCAmelCase: List[str]					   =    hex_string[1:]
		if not all(char in hex_table for char in hex_string				):
				raise ValueError("Non-hexadecimal value was passed to the function"				)
		__lowerCAmelCase: Union[str, Any]					   =    0
		for char in hex_string:
				__lowerCAmelCase: str					   =    1_6 * decimal_number + hex_table[char]
		return -decimal_number if is_negative else decimal_number


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

			testmod()





"""simple docstring"""


from __future__ import annotations






def 					a__					(					__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				)			->			tuple[float, float]:
		assert (
		    c % greatest_common_divisor(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				) == 0
		)  # greatest_common_divisor(a,b) function implemented below
		((__lowerCAmelCase)   ,				(__lowerCAmelCase)   ,				(__lowerCAmelCase)): Dict					   =    extended_gcd(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				)  # extended_gcd(a,b) function implemented below
		__lowerCAmelCase: Optional[int]					   =    c / d
		return (r * x, r * y)






def 					a__					(					__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE = 2				)			->			None:
		((__lowerCAmelCase)   ,				(__lowerCAmelCase)): Optional[Any]					   =    diophantine(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				)  # Initial value
		__lowerCAmelCase: Optional[Any]					   =    greatest_common_divisor(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				)
		__lowerCAmelCase: Any					   =    a // d
		__lowerCAmelCase: str					   =    b // d

		for i in range(__SCREAMING_SNAKE_CASE				):
				__lowerCAmelCase: Dict					   =    xa + i * q
				__lowerCAmelCase: List[str]					   =    ya - i * p
				print(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				)






def 					a__					(					__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				)			->			int:
		if a < b:
				__lowerCAmelCase   ,				__lowerCAmelCase: Any					   =    b, a

		while a % b != 0:
				__lowerCAmelCase   ,				__lowerCAmelCase: List[Any]					   =    b, a % b

		return b






def 					a__					(					__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE				)			->			tuple[int, int, int]:
		assert a >= 0 and b >= 0

		if b == 0:
				__lowerCAmelCase   ,				__lowerCAmelCase   ,				__lowerCAmelCase: List[str]					   =    a, 1, 0
		else:
				((__lowerCAmelCase)   ,				(__lowerCAmelCase)   ,				(__lowerCAmelCase)): Dict					   =    extended_gcd(__SCREAMING_SNAKE_CASE      ,				a % b				)
				__lowerCAmelCase: Dict					   =    q
				__lowerCAmelCase: int					   =    p - q * (a // b)

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

		return (d, x, y)


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

			testmod(name="diophantine", verbose=True)
			testmod(name="diophantine_all_soln", verbose=True)
			testmod(name="extended_gcd", verbose=True)
			testmod(name="greatest_common_divisor", verbose=True)


