




'''simple docstring'''



from __future__ import annotations

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



class 			a       :


     """simple docstring"""






     def __init__(       self  :	Optional[int]							,				snake_case  :	Collection[float] | None = None    )		->							None:







          if components is None:
               __UpperCAmelCase			:				List[Any]													=    []
          __UpperCAmelCase			:				Tuple													=    list(snake_case    )

     def __len__(       self  :	int    )		->							int:
          return len(self.__components    )

     def __str__(       self  :	Dict    )		->							str:
          return "(" + ",".join(map(snake_case							,				self.__components    )    ) + ")"

     def __add__(       self  :	str							,				snake_case  :	Vector    )		->							Vector:
          __UpperCAmelCase			:				int													=    len(self    )
          if size == len(snake_case    ):
               __UpperCAmelCase			:				Tuple													=    [self.__components[i] + other.component(snake_case    ) for i in range(snake_case    )]
               return Vector(snake_case    )
          else:
               raise Exception('''must have the same size'''    )

     def __sub__(       self  :	List[Any]							,				snake_case  :	Vector    )		->							Vector:
          __UpperCAmelCase			:				int													=    len(self    )
          if size == len(snake_case    ):
               __UpperCAmelCase			:				str													=    [self.__components[i] - other.component(snake_case    ) for i in range(snake_case    )]
               return Vector(snake_case    )
          else:  # error case
               raise Exception('''must have the same size'''    )

     @overload
     def __mul__(       self  :	List[str]							,				snake_case  :	float    )		->							Vector:
          ...

     @overload
     def __mul__(       self  :	Any							,				snake_case  :	Vector    )		->							float:
          ...

     def __mul__(       self  :	Optional[Any]							,				snake_case  :	float | Vector    )		->							float | Vector:







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

     def 				lowerCamelCase__				(       self  :	Optional[int]    )		->							Vector:
          return Vector(self.__components    )

     def 				lowerCamelCase__				(       self  :	Union[str, Any]							,				snake_case  :	int    )		->							float:







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

     def 				lowerCamelCase__				(       self  :	Tuple							,				snake_case  :	int							,				snake_case  :	float    )		->							None:
          assert -len(self.__components    ) <= pos < len(self.__components    )
          __UpperCAmelCase			:				int													=    value

     def 				lowerCamelCase__				(       self  :	Optional[int]    )		->							float:







          if len(self.__components    ) == 0:
               raise Exception('''Vector is empty'''    )
          __UpperCAmelCase			:				Union[str, Any]													=    [c**2 for c in self.__components]
          return math.sqrt(sum(snake_case    )    )






     def 				lowerCamelCase__				(       self  :	str							,				snake_case  :	Vector							,				snake_case  :	bool = False    )		->							float:
          __UpperCAmelCase			:				List[str]													=    self * other
          __UpperCAmelCase			:				Optional[Any]													=    self.euclidean_length() * other.euclidean_length()
          if deg:
               return math.degrees(math.acos(num / den    )    )
          else:
               return math.acos(num / den    )




def 			_a			(		_lowercase      :			List[str]						):





     '''simple docstring'''






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




def 			_a			(		_lowercase      :			str    ,      _lowercase      :			Any						):





     '''simple docstring'''






     assert isinstance(_SCREAMING_SNAKE_CASE    ,      _SCREAMING_SNAKE_CASE						) and (isinstance(_SCREAMING_SNAKE_CASE    ,      _SCREAMING_SNAKE_CASE						))
     __UpperCAmelCase			:				List[Any]													=    [0] * dimension
     __UpperCAmelCase			:				List[Any]													=    1
     return Vector(_SCREAMING_SNAKE_CASE						)




def 			_a			(		_lowercase      :			List[str]    ,      _lowercase      :			int    ,      _lowercase      :			str						):





     '''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 			_a			(		_lowercase      :			Union[str, Any]    ,      _lowercase      :			str    ,      _lowercase      :			Optional[int]						):





     '''simple docstring'''






     random.seed(_SCREAMING_SNAKE_CASE						)
     __UpperCAmelCase			:				Union[str, Any]													=    [random.randint(_SCREAMING_SNAKE_CASE    ,      _SCREAMING_SNAKE_CASE						) for _ in range(_SCREAMING_SNAKE_CASE						)]
     return Vector(_SCREAMING_SNAKE_CASE						)



class 			a       :


     """simple docstring"""






     def __init__(       self  :	str							,				snake_case  :	list[list[float]]							,				snake_case  :	int							,				snake_case  :	int    )		->							None:
          __UpperCAmelCase			:				Optional[int]													=    matrix
          __UpperCAmelCase			:				str													=    w
          __UpperCAmelCase			:				Optional[int]													=    h

     def __str__(       self  :	List[Any]    )		->							str:
          __UpperCAmelCase			:				Optional[int]													=    ''''''
          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  :	int							,				snake_case  :	Matrix    )		->							Matrix:







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

     def __sub__(       self  :	Optional[Any]							,				snake_case  :	Matrix    )		->							Matrix:







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

     @overload
     def __mul__(       self  :	Dict							,				snake_case  :	float    )		->							Matrix:
          ...

     @overload
     def __mul__(       self  :	str							,				snake_case  :	Vector    )		->							Vector:
          ...

     def __mul__(       self  :	int							,				snake_case  :	float | Vector    )		->							Vector | Matrix:







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

     def 				lowerCamelCase__				(       self  :	Tuple    )		->							int:
          return self.__height

     def 				lowerCamelCase__				(       self  :	int    )		->							int:
          return self.__width

     def 				lowerCamelCase__				(       self  :	str							,				snake_case  :	int							,				snake_case  :	int    )		->							float:







          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  :	List[str]							,				snake_case  :	int							,				snake_case  :	int							,				snake_case  :	float    )		->							None:







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

     def 				lowerCamelCase__				(       self  :	Any							,				snake_case  :	int							,				snake_case  :	int    )		->							float:







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

     def 				lowerCamelCase__				(       self  :	Dict							,				snake_case  :	int							,				snake_case  :	int    )		->							float:







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






     def 				lowerCamelCase__				(       self  :	List[Any]    )		->							float:







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




def 			_a			(		_lowercase      :			List[str]						):





     '''simple docstring'''






     __UpperCAmelCase			:				Optional[Any]													=    [[0] * n for _ in range(_SCREAMING_SNAKE_CASE						)]
     return Matrix(_SCREAMING_SNAKE_CASE    ,      _SCREAMING_SNAKE_CASE    ,      _SCREAMING_SNAKE_CASE						)




def 			_a			(		_lowercase      :			int    ,      _lowercase      :			Tuple    ,      _lowercase      :			str    ,      _lowercase      :			List[str]						):





     '''simple docstring'''






     random.seed(_SCREAMING_SNAKE_CASE						)
     __UpperCAmelCase			:				Optional[int]													=    [
         [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						)



'''simple docstring'''



from __future__ import annotations




def 			_a			(		_lowercase      :			list						):





     '''simple docstring'''






     if not nums:
          raise ValueError('''List is empty'''						)
     return sum(_lowercase						) / len(_lowercase						)


if __name__ == "__main__":
      import doctest

      doctest.testmod()