


from __future__ import annotations

import math
import random
from collections.abc import Collection
from typing import overload




class    UpperCAmelCase					:




			def __init__(						self							:		str       ,       __magic_name__							:		Collection[float] | None = None						):







						"""simple docstring"""







						if components is None:
									UpperCamelCase         =					[]
						UpperCamelCase         =					list(__magic_name__						)




			def __len__(						self							:		List[Any]						):







						"""simple docstring"""







						return len(self.__components						)




			def __str__(						self							:		int						):







						"""simple docstring"""







						return "(" + ",".join(map(__magic_name__       ,       self.__components						)						) + ")"




			def __add__(						self							:		Dict       ,       __magic_name__							:		Vector						):







						"""simple docstring"""







						UpperCamelCase         =					len(self						)
						if size == len(__magic_name__						):
									UpperCamelCase         =					[self.__components[i] + other.component(__magic_name__						) for i in range(__magic_name__						)]
									return Vector(__magic_name__						)
						else:
									raise Exception("""must have the same size"""						)




			def __sub__(						self							:		Tuple       ,       __magic_name__							:		Vector						):







						"""simple docstring"""







						UpperCamelCase         =					len(self						)
						if size == len(__magic_name__						):
									UpperCamelCase         =					[self.__components[i] - other.component(__magic_name__						) for i in range(__magic_name__						)]
									return Vector(__magic_name__						)
						else:  # error case
									raise Exception("""must have the same size"""						)




			@overload
			def __mul__(						self							:		Tuple       ,       __magic_name__							:		float						):







						"""simple docstring"""







						...




			@overload
			def __mul__(						self							:		Dict       ,       __magic_name__							:		Vector						):







						"""simple docstring"""







						...




			def __mul__(						self							:		Any       ,       __magic_name__							:		float | Vector						):







						"""simple docstring"""







						if isinstance(__magic_name__       ,       (float, int)						):
									UpperCamelCase         =					[c * other for c in self.__components]
									return Vector(__magic_name__						)
						elif isinstance(__magic_name__       ,       __magic_name__						) and len(self						) == len(__magic_name__						):
									UpperCamelCase         =					len(self						)
									UpperCamelCase         =					[self.__components[i] * other.component(__magic_name__						) for i in range(__magic_name__						)]
									return sum(__magic_name__						)
						else:  # error case
									raise Exception("""invalid operand!"""						)




			def   lowerCamelCase_					(						self							:		Optional[int]						):







						"""simple docstring"""







						return Vector(self.__components						)




			def   lowerCamelCase_					(						self							:		Optional[Any]       ,       __magic_name__							:		int						):







						"""simple docstring"""







						if isinstance(__magic_name__       ,       __magic_name__						) and -len(self.__components						) <= i < len(self.__components						):
									return self.__components[i]
						else:
									raise Exception("""index out of range"""						)




			def   lowerCamelCase_					(						self							:		Optional[Any]       ,       __magic_name__							:		int       ,       __magic_name__							:		float						):







						"""simple docstring"""







						assert -len(self.__components						) <= pos < len(self.__components						)
						UpperCamelCase         =					value




			def   lowerCamelCase_					(						self							:		List[Any]						):







						"""simple docstring"""







						if len(self.__components						) == 0:
									raise Exception("""Vector is empty"""						)
						UpperCamelCase         =					[c**2 for c in self.__components]
						return math.sqrt(sum(__magic_name__						)						)





			def   lowerCamelCase_					(						self							:		Union[str, Any]       ,       __magic_name__							:		Vector       ,       __magic_name__							:		bool = False						):







						"""simple docstring"""







						UpperCamelCase         =					self * other
						UpperCamelCase         =					self.euclidean_length() * other.euclidean_length()
						if deg:
									return math.degrees(math.acos(num / den						)						)
						else:
									return math.acos(num / den						)






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			assert isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	)
			return Vector([0] * dimension	)






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int       ,  SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			assert isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	) and (isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	))
			UpperCamelCase         =					[0] * dimension
			UpperCamelCase         =					1
			return Vector(SCREAMING_SNAKE_CASE_	)






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		float       ,  SCREAMING_SNAKE_CASE_   :		Vector       ,  SCREAMING_SNAKE_CASE_   :		Vector	):





			"""simple docstring"""




			assert (
			    isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	)
			    and isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	)
			    and (isinstance(SCREAMING_SNAKE_CASE_       ,  (int, float)	))
			)
			return x * scalar + y






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int       ,  SCREAMING_SNAKE_CASE_   :		int       ,  SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			random.seed(SCREAMING_SNAKE_CASE_	)
			UpperCamelCase         =					[random.randint(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	) for _ in range(SCREAMING_SNAKE_CASE_	)]
			return Vector(SCREAMING_SNAKE_CASE_	)




class    UpperCAmelCase					:




			def __init__(						self							:		Optional[Any]       ,       __magic_name__							:		list[list[float]]       ,       __magic_name__							:		int       ,       __magic_name__							:		int						):







						"""simple docstring"""







						UpperCamelCase         =					matrix
						UpperCamelCase         =					w
						UpperCamelCase         =					h




			def __str__(						self							:		Tuple						):







						"""simple docstring"""







						UpperCamelCase         =					""""""
						for i in range(self.__height						):
									ans += "|"
									for j in range(self.__width						):
												if j < self.__width - 1:
															ans += str(self.__matrix[i][j]						) + ","
												else:
															ans += str(self.__matrix[i][j]						) + "|\n"
						return ans




			def __add__(						self							:		Optional[Any]       ,       __magic_name__							:		Matrix						):







						"""simple docstring"""







						if self.__width == other.width() and self.__height == other.height():
									UpperCamelCase         =					[]
									for i in range(self.__height						):
												UpperCamelCase         =					[
												    self.__matrix[i][j] + other.component(__magic_name__       ,       __magic_name__						)
												    for j in range(self.__width						)
												]
												matrix.append(__magic_name__						)
									return Matrix(__magic_name__       ,       self.__width       ,       self.__height						)
						else:
									raise Exception("""matrix must have the same dimension!"""						)




			def __sub__(						self							:		Optional[Any]       ,       __magic_name__							:		Matrix						):







						"""simple docstring"""







						if self.__width == other.width() and self.__height == other.height():
									UpperCamelCase         =					[]
									for i in range(self.__height						):
												UpperCamelCase         =					[
												    self.__matrix[i][j] - other.component(__magic_name__       ,       __magic_name__						)
												    for j in range(self.__width						)
												]
												matrix.append(__magic_name__						)
									return Matrix(__magic_name__       ,       self.__width       ,       self.__height						)
						else:
									raise Exception("""matrices must have the same dimension!"""						)




			@overload
			def __mul__(						self							:		Optional[int]       ,       __magic_name__							:		float						):







						"""simple docstring"""







						...




			@overload
			def __mul__(						self							:		Tuple       ,       __magic_name__							:		Vector						):







						"""simple docstring"""







						...




			def __mul__(						self							:		Union[str, Any]       ,       __magic_name__							:		float | Vector						):







						"""simple docstring"""







						if isinstance(__magic_name__       ,       __magic_name__						):  # matrix-vector
									if len(__magic_name__						) == self.__width:
												UpperCamelCase         =					zero_vector(self.__height						)
												for i in range(self.__height						):
															UpperCamelCase         =					[
															    self.__matrix[i][j] * other.component(__magic_name__						)
															    for j in range(self.__width						)
															]
															ans.change_component(__magic_name__       ,       sum(__magic_name__						)						)
												return ans
									else:
												raise Exception(
												    """vector must have the same size as the """
												    """number of columns of the matrix!"""						)
						elif isinstance(__magic_name__       ,       (int, float)						):  # matrix-scalar
									UpperCamelCase         =					[
									    [self.__matrix[i][j] * other for j in range(self.__width						)]
									    for i in range(self.__height						)
									]
									return Matrix(__magic_name__       ,       self.__width       ,       self.__height						)
						return None




			def   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						return self.__height




			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						return self.__width




			def   lowerCamelCase_					(						self							:		List[Any]       ,       __magic_name__							:		int       ,       __magic_name__							:		int						):







						"""simple docstring"""







						if 0 <= x < self.__height and 0 <= y < self.__width:
									return self.__matrix[x][y]
						else:
									raise Exception("""change_component: indices out of bounds"""						)




			def   lowerCamelCase_					(						self							:		Optional[int]       ,       __magic_name__							:		int       ,       __magic_name__							:		int       ,       __magic_name__							:		float						):







						"""simple docstring"""







						if 0 <= x < self.__height and 0 <= y < self.__width:
									UpperCamelCase         =					value
						else:
									raise Exception("""change_component: indices out of bounds"""						)




			def   lowerCamelCase_					(						self							:		Tuple       ,       __magic_name__							:		int       ,       __magic_name__							:		int						):







						"""simple docstring"""







						if self.__height != self.__width:
									raise Exception("""Matrix is not square"""						)
						UpperCamelCase         =					self.__matrix[:x] + self.__matrix[x + 1 :]
						for i in range(len(__magic_name__						)						):
									UpperCamelCase         =					minor[i][:y] + minor[i][y + 1 :]
						return Matrix(__magic_name__       ,       self.__width - 1       ,       self.__height - 1						).determinant()




			def   lowerCamelCase_					(						self							:		Optional[int]       ,       __magic_name__							:		int       ,       __magic_name__							:		int						):







						"""simple docstring"""







						if self.__height != self.__width:
									raise Exception("""Matrix is not square"""						)
						if 0 <= x < self.__height and 0 <= y < self.__width:
									return (-1) ** (x + y) * self.minor(__magic_name__       ,       __magic_name__						)
						else:
									raise Exception("""Indices out of bounds"""						)





			def   lowerCamelCase_					(						self							:		int						):







						"""simple docstring"""







						if self.__height != self.__width:
									raise Exception("""Matrix is not square"""						)
						if self.__height < 1:
									raise Exception("""Matrix has no element"""						)
						elif self.__height == 1:
									return self.__matrix[0][0]
						elif self.__height == 2:
									return (
									    self.__matrix[0][0] * self.__matrix[1][1]
									    - self.__matrix[0][1] * self.__matrix[1][0]
									)
						else:
									UpperCamelCase         =					[
									    self.__matrix[0][y] * self.cofactor(0       ,       __magic_name__						) for y in range(self.__width						)
									]
									return sum(__magic_name__						)






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			UpperCamelCase         =					[[0] * n for _ in range(SCREAMING_SNAKE_CASE_	)]
			return Matrix(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	)






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int       ,  SCREAMING_SNAKE_CASE_   :		int       ,  SCREAMING_SNAKE_CASE_   :		int       ,  SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			random.seed(SCREAMING_SNAKE_CASE_	)
			UpperCamelCase         =					[
			    [random.randint(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	) for _ in range(SCREAMING_SNAKE_CASE_	)] for _ in range(SCREAMING_SNAKE_CASE_	)
			]
			return Matrix(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	)



import math
import unittest






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		int	):





			"""simple docstring"""




			assert isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	) and (
			    number >= 0
			), "'number' must been an int and positive"

			if 1 < number < 4:
						# 2 and 3 are primes
						return True
			elif number < 2 or number % 2 == 0 or number % 3 == 0:
						# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
						return False

			# All primes number are in format of 6k +/- 1
			for i in range(5       ,  int(math.sqrt(SCREAMING_SNAKE_CASE_	) + 1	)       ,  6	):
						if number % i == 0 or number % (i + 2) == 0:
									return False
			return True




class    UpperCAmelCase					(       unittest.TestCase    ):




			def   lowerCamelCase_					(						self							:		Any						):







						"""simple docstring"""







						self.assertTrue(is_prime(2						)						)
						self.assertTrue(is_prime(3						)						)
						self.assertTrue(is_prime(5						)						)
						self.assertTrue(is_prime(7						)						)
						self.assertTrue(is_prime(1_1						)						)
						self.assertTrue(is_prime(1_3						)						)
						self.assertTrue(is_prime(1_7						)						)
						self.assertTrue(is_prime(1_9						)						)
						self.assertTrue(is_prime(2_3						)						)
						self.assertTrue(is_prime(2_9						)						)





			def   lowerCamelCase_					(						self							:		Dict						):







						"""simple docstring"""







						with self.assertRaises(__magic_name__						):
									is_prime(-1_9						)
						self.assertFalse(
						    is_prime(0						)       ,       """Zero doesn't have any positive factors, primes must have exactly two."""       ,       )
						self.assertFalse(
						    is_prime(1						)       ,       """One only has 1 positive factor, primes must have exactly two."""       ,       )
						self.assertFalse(is_prime(2 * 2						)						)
						self.assertFalse(is_prime(2 * 3						)						)
						self.assertFalse(is_prime(3 * 3						)						)
						self.assertFalse(is_prime(3 * 5						)						)
						self.assertFalse(is_prime(3 * 5 * 7						)						)


if __name__ == "__main__":
			unittest.main()




