'''simple docstring'''




from __future__ import annotations

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





class 					__magic_name__		:







			def __init__(			self       :						Optional[Any]       ,    lowercase_       :						Collection[float] | None = None					):
										if components is None:
																	lowercase_      :    Tuple       		= []
										lowercase_      :    int       		= list(__UpperCamelCase					)







			def __len__(			self       :						str					):
										return len(self.__components					)







			def __str__(			self       :						Tuple					):
										return "(" + ",".join(map(__UpperCamelCase       ,    self.__components					)					) + ")"







			def __add__(			self       :						Any       ,    lowercase_       :						Vector					):
										lowercase_      :    int       		= len(self					)
										if size == len(__UpperCamelCase					):
																	lowercase_      :    Any       		= [self.__components[i] + other.component(__UpperCamelCase					) for i in range(__UpperCamelCase					)]
																	return Vector(__UpperCamelCase					)
										else:
																	raise Exception("""must have the same size"""					)







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







			@overload
			def __mul__(			self       :						Dict       ,    lowercase_       :						float					):
										...







			@overload
			def __mul__(			self       :						Optional[Any]       ,    lowercase_       :						Vector					):
										...







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







			def 			SCREAMING_SNAKE_CASE_  (			self       :						str					):
										return Vector(self.__components					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Union[str, Any]       ,    lowercase_       :						int					):
										if isinstance(__UpperCamelCase       ,    __UpperCamelCase					) and -len(self.__components					) <= i < len(self.__components					):
																	return self.__components[i]
										else:
																	raise Exception("""index out of range"""					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Dict       ,    lowercase_       :						int       ,    lowercase_       :						float					):
										assert -len(self.__components					) <= pos < len(self.__components					)
										lowercase_      :    List[str]       		= value







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										if len(self.__components					) == 0:
																	raise Exception("""Vector is empty"""					)
										lowercase_      :    Dict       		= [c**2 for c in self.__components]
										return math.sqrt(sum(__UpperCamelCase					)					)







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




def 							lowerCamelCase			(   UpperCAmelCase__ :      int				):
							assert isinstance(UpperCAmelCase__   ,   UpperCAmelCase__				)
							return Vector([0] * dimension				)




def 							lowerCamelCase			(   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int				):
							assert isinstance(UpperCAmelCase__   ,   UpperCAmelCase__				) and (isinstance(UpperCAmelCase__   ,   UpperCAmelCase__				))
							lowercase_      :    Any       		= [0] * dimension
							lowercase_      :    Optional[Any]       		= 1
							return Vector(UpperCAmelCase__				)




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




def 							lowerCamelCase			(   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int				):
							random.seed(UpperCAmelCase__				)
							lowercase_      :    Union[str, Any]       		= [random.randint(UpperCAmelCase__   ,   UpperCAmelCase__				) for _ in range(UpperCAmelCase__				)]
							return Vector(UpperCAmelCase__				)





class 					__magic_name__		:







			def __init__(			self       :						Dict       ,    lowercase_       :						list[list[float]]       ,    lowercase_       :						int       ,    lowercase_       :						int					):
										lowercase_      :    List[Any]       		= matrix
										lowercase_      :    int       		= w
										lowercase_      :    int       		= h







			def __str__(			self       :						Dict					):
										lowercase_      :    List[str]       		= """"""
										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       :						Dict       ,    lowercase_       :						Matrix					):
										if self.__width == other.width() and self.__height == other.height():
																	lowercase_      :    Tuple       		= []
																	for i in range(self.__height					):
																								lowercase_      :    Tuple       		= [
																								    self.__matrix[i][j] + other.component(__UpperCamelCase       ,    __UpperCamelCase					)
																								    for j in range(self.__width					)
																								]
																								matrix.append(__UpperCamelCase					)
																	return Matrix(__UpperCamelCase       ,    self.__width       ,    self.__height					)
										else:
																	raise Exception("""matrix must have the same dimension!"""					)







			def __sub__(			self       :						Tuple       ,    lowercase_       :						Matrix					):
										if self.__width == other.width() and self.__height == other.height():
																	lowercase_      :    List[Any]       		= []
																	for i in range(self.__height					):
																								lowercase_      :    Union[str, Any]       		= [
																								    self.__matrix[i][j] - other.component(__UpperCamelCase       ,    __UpperCamelCase					)
																								    for j in range(self.__width					)
																								]
																								matrix.append(__UpperCamelCase					)
																	return Matrix(__UpperCamelCase       ,    self.__width       ,    self.__height					)
										else:
																	raise Exception("""matrices must have the same dimension!"""					)







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







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







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







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any					):
										return self.__height







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







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







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[int]       ,    lowercase_       :						int       ,    lowercase_       :						int					):
										if self.__height != self.__width:
																	raise Exception("""Matrix is not square"""					)
										lowercase_      :    Tuple       		= self.__matrix[:x] + self.__matrix[x + 1 :]
										for i in range(len(__UpperCamelCase					)					):
																	lowercase_      :    int       		= minor[i][:y] + minor[i][y + 1 :]
										return Matrix(__UpperCamelCase       ,    self.__width - 1       ,    self.__height - 1					).determinant()







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]       ,    lowercase_       :						int       ,    lowercase_       :						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(__UpperCamelCase       ,    __UpperCamelCase					)
										else:
																	raise Exception("""Indices out of bounds"""					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Dict					):
										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:
																	lowercase_      :    Any       		= [
																	    self.__matrix[0][y] * self.cofactor(0       ,    __UpperCamelCase					) for y in range(self.__width					)
																	]
																	return sum(__UpperCamelCase					)




def 							lowerCamelCase			(   UpperCAmelCase__ :      int				):
							lowercase_      :    List[str]       		= [[0] * n for _ in range(UpperCAmelCase__				)]
							return Matrix(UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__				)




def 							lowerCamelCase			(   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      int				):
							random.seed(UpperCAmelCase__				)
							lowercase_      :    Optional[int]       		= [
							    [random.randint(UpperCAmelCase__   ,   UpperCAmelCase__				) for _ in range(UpperCAmelCase__				)] for _ in range(UpperCAmelCase__				)
							]
							return Matrix(UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__				)






'''simple docstring'''




_lowercase		:				int	       =		"ABCDEFGHIJKLMNOPQRSTUVWXYZ"




def 							lowerCamelCase			(   )    ->   None:
							lowercase_      :    List[Any]       		= input("""Enter message: """				)
							lowercase_      :    str       		= input("""Enter key [alphanumeric]: """				)
							lowercase_      :    List[Any]       		= input("""Encrypt/Decrypt [e/d]: """				)

							if mode.lower().startswith("""e"""				):
														lowercase_      :    List[str]       		= """encrypt"""
														lowercase_      :    Optional[int]       		= encrypt_message(UpperCAmelCase__   ,   UpperCAmelCase__				)
							elif mode.lower().startswith("""d"""				):
														lowercase_      :    Any       		= """decrypt"""
														lowercase_      :    Optional[Any]       		= decrypt_message(UpperCAmelCase__   ,   UpperCAmelCase__				)

							print(F'''\n{mode.title()}ed message:'''				)
							print(UpperCAmelCase__				)




def 							lowerCamelCase			(   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      str				)    ->   str:
							return translate_message(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """encrypt"""				)




def 							lowerCamelCase			(   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      str				)    ->   str:
							return translate_message(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """decrypt"""				)




def 							lowerCamelCase			(   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      str				)    ->   str:
							lowercase_      :    Union[str, Any]       		= []
							lowercase_      :    List[Any]       		= 0
							lowercase_      :    str       		= key.upper()

							for symbol in message:
														lowercase_      :    Tuple       		= LETTERS.find(symbol.upper()				)
														if num != -1:
																					if mode == "encrypt":
																												num += LETTERS.find(key[key_index]				)
																					elif mode == "decrypt":
																												num -= LETTERS.find(key[key_index]				)

																					num %= len(UpperCAmelCase__				)

																					if symbol.isupper():
																												translated.append(LETTERS[num]				)
																					elif symbol.islower():
																												translated.append(LETTERS[num].lower()				)

																					key_index += 1
																					if key_index == len(UpperCAmelCase__				):
																												lowercase_      :    Any       		= 0
														else:
																					translated.append(UpperCAmelCase__				)
							return "".join(UpperCAmelCase__				)


if __name__ == "__main__":
						main()





