
"""simple docstring"""




from __future__ import annotations

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

class 						a__		:
   def __init__(     self      ,       _a = None							):

          if components is None:
                 lowercase       :							Tuple									=				[]
          lowercase       :							List[str]									=				list(_a							)
   def __len__(     self							):
          return len(self.__components							)
   def __str__(     self							):
          return "(" + ",".join(map(_a      ,       self.__components							)							) + ")"
   def __add__(     self      ,       _a							):
          lowercase       :							List[str]									=				len(self							)
          if size == len(_a							):
                 lowercase       :							Any									=				[self.__components[i] + other.component(_a							) for i in range(_a							)]
                 return Vector(_a							)
          else:
                 raise Exception("must have the same size"							)
   def __sub__(     self      ,       _a							):
          lowercase       :							Union[str, Any]									=				len(self							)
          if size == len(_a							):
                 lowercase       :							Dict									=				[self.__components[i] - other.component(_a							) for i in range(_a							)]
                 return Vector(_a							)
          else:  # error case
                 raise Exception("must have the same size"							)
   @overload
   def __mul__(     self      ,       _a							):
          ...
   @overload
   def __mul__(     self      ,       _a							):
          ...
   def __mul__(     self      ,       _a							):

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

          if isinstance(_a      ,       _a							) and -len(self.__components							) <= i < len(self.__components							):
                 return self.__components[i]
          else:
                 raise Exception("index out of range"							)
   def      __magic_name__     (     self      ,       _a      ,       _a							):
          assert -len(self.__components							) <= pos < len(self.__components							)
          lowercase       :							str									=				value
   def      __magic_name__     (     self							):

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

   def      __magic_name__     (     self      ,       _a      ,       _a = False							):
          lowercase       :							Tuple									=				self * other
          lowercase       :							Optional[Any]									=				self.euclidean_length() * other.euclidean_length()
          if deg:
                 return math.degrees(math.acos(num / den							)							)
          else:
                 return math.acos(num / den							)


def     __magic_name__      ( __snake_case							:			List[Any]    )					->							Vector:
       assert isinstance(_lowerCamelCase	,					_lowerCamelCase    )
       return Vector([0] * dimension    )


def     __magic_name__      ( __snake_case							:			str	,					__snake_case							:			Any    )					->							Vector:
       assert isinstance(_lowerCamelCase	,					_lowerCamelCase    ) and (isinstance(_lowerCamelCase	,					_lowerCamelCase    ))
       lowercase       :							List[Any]									=				[0] * dimension
       lowercase       :							Union[str, Any]									=				1
       return Vector(_lowerCamelCase    )


def     __magic_name__      ( __snake_case							:			Optional[int]	,					__snake_case							:			Tuple	,					__snake_case							:			Optional[int]    )					->							Vector:
       assert (
           isinstance(_lowerCamelCase	,					_lowerCamelCase    )
           and isinstance(_lowerCamelCase	,					_lowerCamelCase    )
           and (isinstance(_lowerCamelCase	,					(int, float)    ))
       )
       return x * scalar + y


def     __magic_name__      ( __snake_case							:			Optional[int]	,					__snake_case							:			Optional[int]	,					__snake_case							:			Union[str, Any]    )					->							Vector:
       random.seed(_lowerCamelCase    )
       lowercase       :							List[Any]									=				[random.randint(_lowerCamelCase	,					_lowerCamelCase    ) for _ in range(_lowerCamelCase    )]
       return Vector(_lowerCamelCase    )

class 						a__		:
   def __init__(     self      ,       _a      ,       _a      ,       _a							):
          lowercase       :							Tuple									=				matrix
          lowercase       :							List[str]									=				w
          lowercase       :							Union[str, Any]									=				h
   def __str__(     self							):
          lowercase       :							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      ,       _a							):

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

          if self.__width == other.width() and self.__height == other.height():
                 lowercase       :							Optional[Any]									=				[]
                 for i in range(self.__height							):
                        lowercase       :							Union[str, Any]									=				[
                            self.__matrix[i][j] - other.component(_a      ,       _a							)
                            for j in range(self.__width							)
                        ]
                        matrix.append(_a							)
                 return Matrix(_a      ,       self.__width      ,       self.__height							)
          else:
                 raise Exception("matrices must have the same dimension!"							)
   @overload
   def __mul__(     self      ,       _a							):
          ...
   @overload
   def __mul__(     self      ,       _a							):
          ...
   def __mul__(     self      ,       _a							):

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

          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      __magic_name__     (     self      ,       _a      ,       _a      ,       _a							):

          if 0 <= x < self.__height and 0 <= y < self.__width:
                 lowercase       :							Optional[Any]									=				value
          else:
                 raise Exception("change_component: indices out of bounds"							)
   def      __magic_name__     (     self      ,       _a      ,       _a							):

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

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

   def      __magic_name__     (     self							):

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


def     __magic_name__      ( __snake_case							:			Optional[Any]    )					->							Matrix:
       lowercase       :							list[list[float]]									=				[[0] * n for _ in range(_lowerCamelCase    )]
       return Matrix(_lowerCamelCase	,					_lowerCamelCase	,					_lowerCamelCase    )


def     __magic_name__      ( __snake_case							:			List[str]	,					__snake_case							:			Dict	,					__snake_case							:			Optional[int]	,					__snake_case							:			Optional[int]    )					->							Matrix:
       random.seed(_lowerCamelCase    )
       lowercase       :							list[list[float]]									=				[
           [random.randint(_lowerCamelCase	,					_lowerCamelCase    ) for _ in range(_lowerCamelCase    )] for _ in range(_lowerCamelCase    )
       ]
       return Matrix(_lowerCamelCase	,					_lowerCamelCase	,					_lowerCamelCase    )









'''simple docstring'''






from __future__ import annotations







def 					_a						(       _lowerCamelCase    ,	_lowerCamelCase = None    ,	_lowerCamelCase = None ) ->				None:



			"""simple docstring"""


			if start is None:
						__snake_case					:      Optional[Any]							      =     0

			if end is None:
						__snake_case					:      Optional[Any]							      =     len(_lowerCamelCase ) - 1

			if start >= end:
						return

			__snake_case					:      Tuple							      =     (start + end) // 2

			slowsort(_lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase )
			slowsort(_lowerCamelCase    ,	mid + 1    ,	_lowerCamelCase )

			if sequence[end] < sequence[mid]:
						__snake_case      ,     __snake_case					:      str							      =     sequence[mid], sequence[end]

			slowsort(_lowerCamelCase    ,	_lowerCamelCase    ,	end - 1 )


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

	testmod()


