




from __future__ import annotations

import math
import random
from collections.abc import Collection
from typing import overload
class     a__					:






						def __init__(     self	,    _A = None    ):




											"""simple docstring"""



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






						def __len__(     self    ):




											"""simple docstring"""



											return len(self.__components    )






						def __str__(     self    ):




											"""simple docstring"""



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






						def __add__(     self	,    _A    ):




											"""simple docstring"""



											__lowerCAmelCase            = len(self    )
											if size == len(_A    ):
																__lowerCAmelCase            = [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    ):




											"""simple docstring"""



											__lowerCAmelCase            = len(self    )
											if size == len(_A    ):
																__lowerCAmelCase            = [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    ):




											"""simple docstring"""



											...






						@overload
						def __mul__(     self	,    _A    ):




											"""simple docstring"""



											...






						def __mul__(     self	,    _A    ):




											"""simple docstring"""



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






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											return Vector(self.__components    )






						def        __SCREAMING_SNAKE_CASE(     self	,    _A    ):




											"""simple docstring"""



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






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A    ):




											"""simple docstring"""



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






						def        __SCREAMING_SNAKE_CASE(     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(_A    )    )






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A = 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 			_a   (		SCREAMING_SNAKE_CASE_							:       int  ):
					assert isinstance(SCREAMING_SNAKE_CASE_   ,   SCREAMING_SNAKE_CASE_  )
					return Vector([0] * dimension  )







def 			_a   (		SCREAMING_SNAKE_CASE_							:       int   ,   SCREAMING_SNAKE_CASE_							:       int  ):
					assert isinstance(SCREAMING_SNAKE_CASE_   ,   SCREAMING_SNAKE_CASE_  ) and (isinstance(SCREAMING_SNAKE_CASE_   ,   SCREAMING_SNAKE_CASE_  ))
					__lowerCAmelCase            = [0] * dimension
					__lowerCAmelCase            = 1
					return Vector(SCREAMING_SNAKE_CASE_  )







def 			_a   (		SCREAMING_SNAKE_CASE_							:       float   ,   SCREAMING_SNAKE_CASE_							:       Vector   ,   SCREAMING_SNAKE_CASE_							:       Vector  ):
					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   (		SCREAMING_SNAKE_CASE_							:       int   ,   SCREAMING_SNAKE_CASE_							:       int   ,   SCREAMING_SNAKE_CASE_							:       int  ):
					random.seed(SCREAMING_SNAKE_CASE_  )
					__lowerCAmelCase            = [random.randint(SCREAMING_SNAKE_CASE_   ,   SCREAMING_SNAKE_CASE_  ) for _ in range(SCREAMING_SNAKE_CASE_  )]
					return Vector(SCREAMING_SNAKE_CASE_  )
class     a__					:






						def __init__(     self	,    _A	,    _A	,    _A    ):




											"""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	,    _A    ):




											"""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(_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    ):




											"""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(_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    ):




											"""simple docstring"""



											...






						@overload
						def __mul__(     self	,    _A    ):




											"""simple docstring"""



											...






						def __mul__(     self	,    _A    ):




											"""simple docstring"""



											if isinstance(_A	,    _A    ):  # matrix-vector
																if len(_A    ) == self.__width:
																					__lowerCAmelCase            = zero_vector(self.__height    )
																					for i in range(self.__height    ):
																										__lowerCAmelCase            = [
																										    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
																__lowerCAmelCase            = [
																    [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        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											return self.__height






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											return self.__width






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A    ):




											"""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        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A	,    _A    ):




											"""simple docstring"""



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






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A    ):




											"""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(_A    )    ):
																__lowerCAmelCase            = minor[i][:y] + minor[i][y + 1 :]
											return Matrix(_A	,    self.__width - 1	,    self.__height - 1    ).determinant()






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A    ):




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






						def        __SCREAMING_SNAKE_CASE(     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	,    _A    ) for y in range(self.__width    )
																]
																return sum(_A    )







def 			_a   (		SCREAMING_SNAKE_CASE_							:       int  ):
					__lowerCAmelCase            = [[0] * n for _ in range(SCREAMING_SNAKE_CASE_  )]
					return Matrix(SCREAMING_SNAKE_CASE_   ,   SCREAMING_SNAKE_CASE_   ,   SCREAMING_SNAKE_CASE_  )







def 			_a   (		SCREAMING_SNAKE_CASE_							:       int   ,   SCREAMING_SNAKE_CASE_							:       int   ,   SCREAMING_SNAKE_CASE_							:       int   ,   SCREAMING_SNAKE_CASE_							:       int  ):
					random.seed(SCREAMING_SNAKE_CASE_  )
					__lowerCAmelCase            = [
					    [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_  )










import json
from typing import Iterator, List, Union

from tokenizers import AddedToken, Regex, Tokenizer, decoders, normalizers, pre_tokenizers, trainers
from tokenizers.implementations.base_tokenizer import BaseTokenizer
from tokenizers.models import Unigram
from tokenizers.processors import TemplateProcessing
class     a__					(      snake_case__   ):






						def __init__(     self	,    _A = "▁"	,    _A = True	,    _A = "<unk>"	,    _A = "</s>"	,    _A = "<pad>"	,    ):




											"""simple docstring"""



											__lowerCAmelCase            = {
											    "pad": {"id": 0, "token": pad_token},
											    "eos": {"id": 1, "token": eos_token},
											    "unk": {"id": 2, "token": unk_token},
											}

											__lowerCAmelCase            = [None] * len(self.special_tokens    )
											for token_dict in self.special_tokens.values():
																__lowerCAmelCase            = token_dict["token"]

											__lowerCAmelCase            = Tokenizer(Unigram()    )

											__lowerCAmelCase            = normalizers.Sequence(
											    [
											        normalizers.Nmt(),
											        normalizers.NFKC(),
											        normalizers.Replace(Regex(" {2,}"    )	,    " "    ),
											        normalizers.Lowercase(),
											    ]    )
											__lowerCAmelCase            = pre_tokenizers.Sequence(
											    [
											        pre_tokenizers.Metaspace(replacement=_A	,    add_prefix_space=_A    ),
											        pre_tokenizers.Digits(individual_digits=_A    ),
											        pre_tokenizers.Punctuation(),
											    ]    )
											__lowerCAmelCase            = decoders.Metaspace(replacement=_A	,    add_prefix_space=_A    )

											__lowerCAmelCase            = TemplateProcessing(
											    single=f"""$A {self.special_tokens['eos']['token']}"""	,    special_tokens=[(self.special_tokens["eos"]["token"], self.special_tokens["eos"]["id"])]	,    )

											__lowerCAmelCase            = {
											    "model": "SentencePieceUnigram",
											    "replacement": replacement,
											    "add_prefix_space": add_prefix_space,
											}

											super().__init__(_A	,    _A    )






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A = 8_0_0_0	,    _A = True	,    ):




											"""simple docstring"""



											__lowerCAmelCase            = trainers.UnigramTrainer(
											    vocab_size=_A	,    special_tokens=self.special_tokens_list	,    show_progress=_A	,    )

											if isinstance(_A	,    _A    ):
																__lowerCAmelCase            = [files]
											self._tokenizer.train(_A	,    trainer=_A    )

											self.add_unk_id()






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A = 8_0_0_0	,    _A = True	,    ):




											"""simple docstring"""



											__lowerCAmelCase            = trainers.UnigramTrainer(
											    vocab_size=_A	,    special_tokens=self.special_tokens_list	,    show_progress=_A	,    )

											self._tokenizer.train_from_iterator(_A	,    trainer=_A    )

											self.add_unk_id()






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											__lowerCAmelCase            = json.loads(self._tokenizer.to_str()    )

											__lowerCAmelCase            = self.special_tokens["unk"]["id"]

											__lowerCAmelCase            = Tokenizer.from_str(json.dumps(_A    )    )




