





from __future__ import annotations

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






class 					__A    :

			'''simple docstring'''







			def __init__(    self       ,  __lowerCAmelCase = None							):



				'''simple docstring'''







				if components is None:
					lowerCamelCase__								=		[]
				lowerCamelCase__								=		list(__lowerCAmelCase							)





			def __len__(    self							):



				'''simple docstring'''







				return len(self.__components							)





			def __str__(    self							):



				'''simple docstring'''







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





			def __add__(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







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





			def __sub__(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







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





			@overload
			def __mul__(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







				...





			@overload
			def __mul__(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







				...





			def __mul__(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







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





			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				return Vector(self.__components							)





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







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





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase							):



				'''simple docstring'''







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





			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







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





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase = False							):



				'''simple docstring'''







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





def lowerCAmelCase__(__snake_case							)				->      Vector:







	'''simple docstring'''







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





def lowerCAmelCase__(__snake_case       ,__snake_case							)				->      Vector:







	'''simple docstring'''







	assert isinstance(__snake_case       ,__snake_case							) and (isinstance(__snake_case       ,__snake_case							))
	lowerCamelCase__								=		[0] * dimension
	lowerCamelCase__								=		1
	return Vector(__snake_case							)





def lowerCAmelCase__(__snake_case       ,__snake_case       ,__snake_case							)				->      Vector:







	'''simple docstring'''







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





def lowerCAmelCase__(__snake_case       ,__snake_case       ,__snake_case							)				->      Vector:







	'''simple docstring'''







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






class 					__A    :

			'''simple docstring'''







			def __init__(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase       ,  __lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__								=		matrix
				lowerCamelCase__								=		w
				lowerCamelCase__								=		h





			def __str__(    self							):



				'''simple docstring'''







				lowerCamelCase__								=		''''''
				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       ,  __lowerCAmelCase							):



				'''simple docstring'''







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





			def __sub__(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







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





			@overload
			def __mul__(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







				...





			@overload
			def __mul__(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







				...





			def __mul__(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







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





			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				return self.__height





			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				return self.__width





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase							):



				'''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       ,  __lowerCAmelCase       ,  __lowerCAmelCase       ,  __lowerCAmelCase							):



				'''simple docstring'''







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





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase							):



				'''simple docstring'''







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





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase							):



				'''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(__lowerCAmelCase       ,  __lowerCAmelCase							)
				else:
					raise Exception('''Indices out of bounds'''							)





			def 		__lowerCamelCase				(    self							):



				'''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:
					lowerCamelCase__								=		[
					    self.__matrix[0][y] * self.cofactor(0       ,  __lowerCAmelCase							) for y in range(self.__width							)
					]
					return sum(__lowerCAmelCase							)





def lowerCAmelCase__(__snake_case							)				->      Matrix:







	'''simple docstring'''







	lowerCamelCase__								=		[[0] * n for _ in range(__snake_case							)]
	return Matrix(__snake_case       ,__snake_case       ,__snake_case							)





def lowerCAmelCase__(__snake_case       ,__snake_case       ,__snake_case       ,__snake_case							)				->      Matrix:







	'''simple docstring'''







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










def lowerCAmelCase__(__snake_case       ,__snake_case							)				->      float:







	'''simple docstring'''







	if mass < 0:
		raise ValueError('''The mass of a body cannot be negative'''							)
	return 0.5 * mass * abs(__snake_case							) * abs(__snake_case							)


if __name__ == "__main__":
			import doctest

			doctest.testmod(verbose=True)



