from __future__ import annotations

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




class   _UpperCamelCase :


			"""simple docstring"""






			def __init__(  self ,  lowerCAmelCase__ = None		)	->   None:

							'''simple docstring'''


							if components is None:
											__lowercase					     =				[]
							__lowercase					     =				list(lowerCAmelCase__		)





			def __len__(  self		)	->   int:

							'''simple docstring'''


							return len(self.__components		)





			def __str__(  self		)	->   str:

							'''simple docstring'''


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





			def __add__(  self ,  lowerCAmelCase__		)	->   Vector:

							'''simple docstring'''


							__lowercase					     =				len(self		)
							if size == len(lowerCAmelCase__		):
											__lowercase					     =				[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 ,  lowerCAmelCase__		)	->   Vector:

							'''simple docstring'''


							__lowercase					     =				len(self		)
							if size == len(lowerCAmelCase__		):
											__lowercase					     =				[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 ,  lowerCAmelCase__		)	->   Vector:

							'''simple docstring'''


							...





			@overload
			def __mul__(  self ,  lowerCAmelCase__		)	->   float:

							'''simple docstring'''


							...





			def __mul__(  self ,  lowerCAmelCase__		)	->   float | Vector:

							'''simple docstring'''


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





			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   Vector:

							'''simple docstring'''


							return Vector(self.__components		)





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__		)	->   float:

							'''simple docstring'''


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





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   None:

							'''simple docstring'''


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





			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   float:

							'''simple docstring'''


							if len(self.__components		) == 0:
											raise Exception('''Vector is empty'''		)
							__lowercase					     =				[c**2 for c in self.__components]
							return math.sqrt(sum(lowerCAmelCase__		)		)





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__ = False		)	->   float:

							'''simple docstring'''


							__lowercase					     =				self * other
							__lowercase					     =				self.euclidean_length() * other.euclidean_length()
							if deg:
											return math.degrees(math.acos(num / den		)		)
							else:
											return math.acos(num / den		)





def 							UpperCAmelCase		(       lowercase				):







				"""simple docstring"""



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





def 							UpperCAmelCase		(       lowercase				,     lowercase				):







				"""simple docstring"""



				assert isinstance(lowercase				,     lowercase				) and (isinstance(lowercase				,     lowercase				))
				__lowercase					     =				[0] * dimension
				__lowercase					     =				1
				return Vector(lowercase				)





def 							UpperCAmelCase		(       lowercase				,     lowercase				,     lowercase				):







				"""simple docstring"""



				assert (
				    isinstance(lowercase				,     lowercase				)
				    and isinstance(lowercase				,     lowercase				)
				    and (isinstance(lowercase				,     (int, float)				))
				)
				return x * scalar + y





def 							UpperCAmelCase		(       lowercase				,     lowercase				,     lowercase				):







				"""simple docstring"""



				random.seed(lowercase				)
				__lowercase					     =				[random.randint(lowercase				,     lowercase				) for _ in range(lowercase				)]
				return Vector(lowercase				)




class   _UpperCamelCase :


			"""simple docstring"""






			def __init__(  self ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   None:

							'''simple docstring'''


							__lowercase					     =				matrix
							__lowercase					     =				w
							__lowercase					     =				h





			def __str__(  self		)	->   str:

							'''simple docstring'''


							__lowercase					     =				''''''
							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 ,  lowerCAmelCase__		)	->   Matrix:

							'''simple docstring'''


							if self.__width == other.width() and self.__height == other.height():
											__lowercase					     =				[]
											for i in range(self.__height		):
															__lowercase					     =				[
															    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 ,  lowerCAmelCase__		)	->   Matrix:

							'''simple docstring'''


							if self.__width == other.width() and self.__height == other.height():
											__lowercase					     =				[]
											for i in range(self.__height		):
															__lowercase					     =				[
															    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 ,  lowerCAmelCase__		)	->   Matrix:

							'''simple docstring'''


							...





			@overload
			def __mul__(  self ,  lowerCAmelCase__		)	->   Vector:

							'''simple docstring'''


							...





			def __mul__(  self ,  lowerCAmelCase__		)	->   Vector | Matrix:

							'''simple docstring'''


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

							'''simple docstring'''


							return self.__height





			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   int:

							'''simple docstring'''


							return self.__width





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   float:

							'''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 ,  lowerCAmelCase__ ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   None:

							'''simple docstring'''


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





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   float:

							'''simple docstring'''


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





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   float:

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





			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   float:

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





def 							UpperCAmelCase		(       lowercase				):







				"""simple docstring"""



				__lowercase					     =				[[0] * n for _ in range(lowercase				)]
				return Matrix(lowercase				,     lowercase				,     lowercase				)





def 							UpperCAmelCase		(       lowercase				,     lowercase				,     lowercase				,     lowercase				):







				"""simple docstring"""



				random.seed(lowercase				)
				__lowercase					     =				[
				    [random.randint(lowercase				,     lowercase				) for _ in range(lowercase				)] for _ in range(lowercase				)
				]
				return Matrix(lowercase				,     lowercase				,     lowercase				)
import datasets


__a    :	Optional[Any]         =    """\
@InProceedings{conneau2018xnli,
  author = \"Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin\",
  title = \"XNLI: Evaluating Cross-lingual Sentence Representations\",
  booktitle = \"Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing\",
  year = \"2018\",
  publisher = \"Association for Computational Linguistics\",
  location = \"Brussels, Belgium\",
}
"""

__a    :	Optional[Any]         =    """\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
"""

__a    :	str         =    """
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    'accuracy': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric(\"xnli\")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}
"""





def 							UpperCAmelCase		(       lowercase				,     lowercase				):







				"""simple docstring"""



				return (preds == labels).mean()




@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION		,_KWARGS_DESCRIPTION					)
class   _UpperCamelCase (		datasets.Metric					):


			"""simple docstring"""






			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   str:

							'''simple docstring'''


							return datasets.MetricInfo(
							    description=_DESCRIPTION ,  citation=_CITATION ,  inputs_description=_KWARGS_DESCRIPTION ,  features=datasets.Features(
							        {
							            '''predictions''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''		),
							            '''references''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''		),
							        }		) ,  codebase_urls=[] ,  reference_urls=[] ,  format='''numpy''' ,  )





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   Dict:

							'''simple docstring'''


							return {"accuracy": simple_accuracy(lowerCAmelCase__ ,  lowerCAmelCase__		)}