

from __future__ import annotations

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





class 			_SCREAMING_SNAKE_CASE :







   '''simple docstring'''




   def __init__(       self					:			List[Any]     , __lowerCamelCase					:			Collection[float] | None = None			):
       if components is None:
           SCREAMING_SNAKE_CASE										=   []
       SCREAMING_SNAKE_CASE										=   list(__lowerCamelCase			)





   def __len__(       self					:			Optional[int]			):
       return len(self.__components			)





   def __str__(       self					:			List[str]			):
       return "(" + ",".join(map(__lowerCamelCase     , self.__components			)			) + ")"





   def __add__(       self					:			Optional[Any]     , __lowerCamelCase					:			Vector			):
       SCREAMING_SNAKE_CASE										=   len(self			)
       if size == len(__lowerCamelCase			):
           SCREAMING_SNAKE_CASE										=   [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					:			str     , __lowerCamelCase					:			Vector			):
       SCREAMING_SNAKE_CASE										=   len(self			)
       if size == len(__lowerCamelCase			):
           SCREAMING_SNAKE_CASE										=   [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					:			int     , __lowerCamelCase					:			float			):
       ...





   @overload
   def __mul__(       self					:			str     , __lowerCamelCase					:			Vector			):
       ...





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





   def      _snake_case		(       self					:			Any			):
       return Vector(self.__components			)





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





   def      _snake_case		(       self					:			Optional[Any]     , __lowerCamelCase					:			int     , __lowerCamelCase					:			float			):
       assert -len(self.__components			) <= pos < len(self.__components			)
       SCREAMING_SNAKE_CASE										=   value





   def      _snake_case		(       self					:			Dict			):
       if len(self.__components			) == 0:
           raise Exception("Vector is empty"			)
       SCREAMING_SNAKE_CASE										=   [c**2 for c in self.__components]
       return math.sqrt(sum(__lowerCamelCase			)			)





   def      _snake_case		(       self					:			Optional[int]     , __lowerCamelCase					:			Vector     , __lowerCamelCase					:			bool = False			):
       SCREAMING_SNAKE_CASE										=   self * other
       SCREAMING_SNAKE_CASE										=   self.euclidean_length() * other.euclidean_length()
       if deg:
           return math.degrees(math.acos(num / den			)			)
       else:
           return math.acos(num / den			)





def 	__a     (      A__			:  int       ):
    assert isinstance(A__			,  A__       )
    return Vector([0] * dimension       )





def 	__a     (      A__			:  int			,  A__			:  int       ):
    assert isinstance(A__			,  A__       ) and (isinstance(A__			,  A__       ))
    SCREAMING_SNAKE_CASE										=   [0] * dimension
    SCREAMING_SNAKE_CASE										=   1
    return Vector(A__       )





def 	__a     (      A__			:  float			,  A__			:  Vector			,  A__			:  Vector       ):
    assert (
        isinstance(A__			,  A__       )
        and isinstance(A__			,  A__       )
        and (isinstance(A__			,  (int, float)       ))
    )
    return x * scalar + y





def 	__a     (      A__			:  int			,  A__			:  int			,  A__			:  int       ):
    random.seed(A__       )
    SCREAMING_SNAKE_CASE										=   [random.randint(A__			,  A__       ) for _ in range(A__       )]
    return Vector(A__       )





class 			_SCREAMING_SNAKE_CASE :







   '''simple docstring'''




   def __init__(       self					:			str     , __lowerCamelCase					:			list[list[float]]     , __lowerCamelCase					:			int     , __lowerCamelCase					:			int			):
       SCREAMING_SNAKE_CASE										=   matrix
       SCREAMING_SNAKE_CASE										=   w
       SCREAMING_SNAKE_CASE										=   h





   def __str__(       self					:			Any			):
       SCREAMING_SNAKE_CASE										=   ""
       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					:			Tuple     , __lowerCamelCase					:			Matrix			):
       if self.__width == other.width() and self.__height == other.height():
           SCREAMING_SNAKE_CASE										=   []
           for i in range(self.__height			):
               SCREAMING_SNAKE_CASE										=   [
                   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					:			Optional[Any]     , __lowerCamelCase					:			Matrix			):
       if self.__width == other.width() and self.__height == other.height():
           SCREAMING_SNAKE_CASE										=   []
           for i in range(self.__height			):
               SCREAMING_SNAKE_CASE										=   [
                   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					:			Optional[int]     , __lowerCamelCase					:			float			):
       ...





   @overload
   def __mul__(       self					:			List[str]     , __lowerCamelCase					:			Vector			):
       ...





   def __mul__(       self					:			List[str]     , __lowerCamelCase					:			float | Vector			):
       if isinstance(__lowerCamelCase     , __lowerCamelCase			):  # matrix-vector
           if len(__lowerCamelCase			) == self.__width:
               SCREAMING_SNAKE_CASE										=   zero_vector(self.__height			)
               for i in range(self.__height			):
                   SCREAMING_SNAKE_CASE										=   [
                       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
           SCREAMING_SNAKE_CASE										=   [
               [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      _snake_case		(       self					:			Any			):
       return self.__height





   def      _snake_case		(       self					:			Tuple			):
       return self.__width





   def      _snake_case		(       self					:			Tuple     , __lowerCamelCase					:			int     , __lowerCamelCase					:			int			):
       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      _snake_case		(       self					:			Optional[int]     , __lowerCamelCase					:			int     , __lowerCamelCase					:			int     , __lowerCamelCase					:			float			):
       if 0 <= x < self.__height and 0 <= y < self.__width:
           SCREAMING_SNAKE_CASE										=   value
       else:
           raise Exception("change_component: indices out of bounds"			)





   def      _snake_case		(       self					:			List[Any]     , __lowerCamelCase					:			int     , __lowerCamelCase					:			int			):
       if self.__height != self.__width:
           raise Exception("Matrix is not square"			)
       SCREAMING_SNAKE_CASE										=   self.__matrix[:x] + self.__matrix[x + 1 :]
       for i in range(len(__lowerCamelCase			)			):
           SCREAMING_SNAKE_CASE										=   minor[i][:y] + minor[i][y + 1 :]
       return Matrix(__lowerCamelCase     , self.__width - 1     , self.__height - 1			).determinant()





   def      _snake_case		(       self					:			Any     , __lowerCamelCase					:			int     , __lowerCamelCase					:			int			):
       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      _snake_case		(       self					:			Any			):
       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:
           SCREAMING_SNAKE_CASE										=   [
               self.__matrix[0][y] * self.cofactor(0     , __lowerCamelCase			) for y in range(self.__width			)
           ]
           return sum(__lowerCamelCase			)





def 	__a     (      A__			:  int       ):
    SCREAMING_SNAKE_CASE										=   [[0] * n for _ in range(A__       )]
    return Matrix(A__			,  A__			,  A__       )





def 	__a     (      A__			:  int			,  A__			:  int			,  A__			:  int			,  A__			:  int       ):
    random.seed(A__       )
    SCREAMING_SNAKE_CASE										=   [
        [random.randint(A__			,  A__       ) for _ in range(A__       )] for _ in range(A__       )
    ]
    return Matrix(A__			,  A__			,  A__       )



'''simple docstring'''
__SCREAMING_SNAKE_CASE					:				Optional[int]									=		{
    '''a''': '''AAAAA''',
    '''b''': '''AAAAB''',
    '''c''': '''AAABA''',
    '''d''': '''AAABB''',
    '''e''': '''AABAA''',
    '''f''': '''AABAB''',
    '''g''': '''AABBA''',
    '''h''': '''AABBB''',
    '''i''': '''ABAAA''',
    '''j''': '''BBBAA''',
    '''k''': '''ABAAB''',
    '''l''': '''ABABA''',
    '''m''': '''ABABB''',
    '''n''': '''ABBAA''',
    '''o''': '''ABBAB''',
    '''p''': '''ABBBA''',
    '''q''': '''ABBBB''',
    '''r''': '''BAAAA''',
    '''s''': '''BAAAB''',
    '''t''': '''BAABA''',
    '''u''': '''BAABB''',
    '''v''': '''BBBAB''',
    '''w''': '''BABAA''',
    '''x''': '''BABAB''',
    '''y''': '''BABBA''',
    '''z''': '''BABBB''',
    ''' ''': ''' ''',
}


__SCREAMING_SNAKE_CASE					:				Tuple									=		{value: key for key, value in encode_dict.items()}







def       a_				(	UpperCamelCase_ ):
							A_			    =		""
							for letter in word.lower():
														if letter.isalpha() or letter == " ":
																					encoded += encode_dict[letter]
														else:
																					raise Exception("encode() accepts only letters of the alphabet and spaces" )
							return encoded







def       a_				(	UpperCamelCase_ ):
							if set(UpperCamelCase_ ) - {"A", "B", " "} != set():
														raise Exception("decode() accepts only 'A', 'B' and spaces" )
							A_			    =		""
							for word in coded.split():
														while len(UpperCamelCase_ ) != 0:
																					decoded += decode_dict[word[:5]]
																					A_			    =		word[5:]
														decoded += " "
							return decoded.strip()


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

							testmod()





