



from abc import ABC, abstractmethod
from typing import List, Optional

class 				snake_case__(_UpperCamelCase      ):

					"""simple docstring"""






					def __init__(							self :     List[str]					):
									# test for the above condition
									self.test()







					def 			snake_case					(							self :     Union[str, Any]					):
									lowercase__					:   List[Any]													=					0
									lowercase__					:   str													=					False
									while not completed:
													if counter == 1:
																	self.reset()
													lowercase__					:   List[Any]													=					self.advance()
													if not self.does_advance(SCREAMING_SNAKE_CASE					):
																	raise Exception(
																	    "Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true."					)

													lowercase__							,							lowercase__							,							lowercase__					:   str													=					self.update(SCREAMING_SNAKE_CASE					)
													counter += 1

													if counter > 10_000:
																	raise Exception("update() does not fulfill the constraint."					)

									if self.remaining() != 0:
													raise Exception("Custom Constraint is not defined correctly."					)







					@abstractmethod
					def 			snake_case					(							self :     Any					):
									raise NotImplementedError(
									    f"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""					)







					@abstractmethod
					def 			snake_case					(							self :     Optional[Any]				,       SCREAMING_SNAKE_CASE :     int					):
									raise NotImplementedError(
									    f"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""					)







					@abstractmethod
					def 			snake_case					(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     int					):
									raise NotImplementedError(
									    f"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""					)







					@abstractmethod
					def 			snake_case					(							self :     Dict					):
									raise NotImplementedError(
									    f"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""					)







					@abstractmethod
					def 			snake_case					(							self :     List[Any]					):
									raise NotImplementedError(
									    f"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""					)







					@abstractmethod
					def 			snake_case					(							self :     List[str]				,       SCREAMING_SNAKE_CASE :     Tuple=False					):
									raise NotImplementedError(
									    f"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""					)






class 				snake_case__(_UpperCamelCase      ):

					"""simple docstring"""






					def __init__(							self :     Optional[Any]				,       SCREAMING_SNAKE_CASE :     List[int]					):
									super(SCREAMING_SNAKE_CASE				,       self					).__init__()

									if not isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					) or len(SCREAMING_SNAKE_CASE					) == 0:
													raise ValueError(f"""`token_ids` has to be a non-empty list, but is {token_ids}."""					)
									if any((not isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					) or token_id < 0) for token_id in token_ids					):
													raise ValueError(f"""Each list in `token_ids` has to be a list of positive integers, but is {token_ids}."""					)

									lowercase__					:   Optional[Any]													=					token_ids

									lowercase__					:   Tuple													=					len(self.token_ids					)
									lowercase__					:   Dict													=					-1  # the index of the currently fulfilled step
									lowercase__					:   List[str]													=					False







					def 			snake_case					(							self :     int					):
									if self.completed:
													return None
									return self.token_ids[self.fulfilled_idx + 1]







					def 			snake_case					(							self :     Dict				,       SCREAMING_SNAKE_CASE :     int					):
									if not isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
													raise ValueError(f"""`token_id` has to be an `int`, but is {token_id} of type {type(SCREAMING_SNAKE_CASE					)}"""					)

									if self.completed:
													return False

									return token_id == self.token_ids[self.fulfilled_idx + 1]







					def 			snake_case					(							self :     Union[str, Any]				,       SCREAMING_SNAKE_CASE :     int					):
									if not isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
													raise ValueError(f"""`token_id` has to be an `int`, but is {token_id} of type {type(SCREAMING_SNAKE_CASE					)}"""					)

									lowercase__					:   int													=					False
									lowercase__					:   Optional[Any]													=					False
									lowercase__					:   Union[str, Any]													=					False

									if self.does_advance(SCREAMING_SNAKE_CASE					):
													self.fulfilled_idx += 1
													lowercase__					:   Tuple													=					True
													if self.fulfilled_idx == (self.seqlen - 1):
																	lowercase__					:   Union[str, Any]													=					True
													lowercase__					:   Optional[Any]													=					completed
									else:
													# failed to make progress.
													lowercase__					:   List[Any]													=					True
													self.reset()
									return stepped, completed, reset







					def 			snake_case					(							self :     Optional[int]					):
									lowercase__					:   Any													=					False
									lowercase__					:   List[str]													=					0







					def 			snake_case					(							self :     int					):
									return self.seqlen - (self.fulfilled_idx + 1)







					def 			snake_case					(							self :     str				,       SCREAMING_SNAKE_CASE :     Any=False					):
									lowercase__					:   List[str]													=					PhrasalConstraint(self.token_ids					)

									if stateful:
													lowercase__					:   List[Any]													=					self.seqlen
													lowercase__					:   Dict													=					self.fulfilled_idx
													lowercase__					:   str													=					self.completed

									return new_constraint






class 				snake_case__:

					"""simple docstring"""






					def __init__(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     List[List[int]]				,       SCREAMING_SNAKE_CASE :     Optional[Any]=True					):
									lowercase__					:   Dict													=					max([len(SCREAMING_SNAKE_CASE					) for one in nested_token_ids]					)

									lowercase__					:   str													=					{}
									for token_ids in nested_token_ids:
													lowercase__					:   Union[str, Any]													=					root
													for tidx, token_id in enumerate(SCREAMING_SNAKE_CASE					):
																	if token_id not in level:
																					lowercase__					:   str													=					{}

																	lowercase__					:   Optional[Any]													=					level[token_id]

									if no_subsets and self.has_subsets(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
													raise ValueError(
													    "Each list in `nested_token_ids` can't be a complete subset of another list, but is"
													    f""" {nested_token_ids}."""					)

									lowercase__					:   Any													=					root







					def 			snake_case					(							self :     Any				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   str													=					self.trie

									for current_token in current_seq:
													lowercase__					:   Optional[Any]													=					start[current_token]

									lowercase__					:   Optional[Any]													=					list(start.keys()					)

									return next_tokens







					def 			snake_case					(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     Any					):
									lowercase__					:   Optional[Any]													=					self.next_tokens(SCREAMING_SNAKE_CASE					)

									return len(SCREAMING_SNAKE_CASE					) == 0







					def 			snake_case					(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     List[str]					):
									lowercase__					:   Optional[Any]													=					list(root.values()					)
									if len(SCREAMING_SNAKE_CASE					) == 0:
													return 1
									else:
													return sum([self.count_leaves(SCREAMING_SNAKE_CASE					) for nn in next_nodes]					)







					def 			snake_case					(							self :     Any				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   List[str]													=					self.count_leaves(SCREAMING_SNAKE_CASE					)
									return len(SCREAMING_SNAKE_CASE					) != leaf_count






class 				snake_case__(_UpperCamelCase      ):

					"""simple docstring"""






					def __init__(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     List[List[int]]					):
									super(SCREAMING_SNAKE_CASE				,       self					).__init__()

									if not isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					) or len(SCREAMING_SNAKE_CASE					) == 0:
													raise ValueError(f"""`nested_token_ids` has to be a non-empty list, but is {nested_token_ids}."""					)
									if any(not isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					) for token_ids in nested_token_ids					):
													raise ValueError(f"""`nested_token_ids` has to be a list of lists, but is {nested_token_ids}."""					)
									if any(
									    any((not isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					) or token_id < 0) for token_id in token_ids					)
									    for token_ids in nested_token_ids					):
													raise ValueError(
													    f"""Each list in `nested_token_ids` has to be a list of positive integers, but is {nested_token_ids}."""					)

									lowercase__					:   int													=					DisjunctiveTrie(SCREAMING_SNAKE_CASE					)
									lowercase__					:   Optional[Any]													=					nested_token_ids

									lowercase__					:   Tuple													=					self.trie.max_height
									lowercase__					:   Tuple													=					[]
									lowercase__					:   List[str]													=					False







					def 			snake_case					(							self :     Tuple					):
									lowercase__					:   int													=					self.trie.next_tokens(self.current_seq					)

									if len(SCREAMING_SNAKE_CASE					) == 0:
													return None
									else:
													return token_list







					def 			snake_case					(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     int					):
									if not isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
													raise ValueError(f"""`token_id` is supposed to be type `int`, but is {token_id} of type {type(SCREAMING_SNAKE_CASE					)}"""					)

									lowercase__					:   Optional[int]													=					self.trie.next_tokens(self.current_seq					)

									return token_id in next_tokens







					def 			snake_case					(							self :     Optional[Any]				,       SCREAMING_SNAKE_CASE :     int					):
									if not isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
													raise ValueError(f"""`token_id` is supposed to be type `int`, but is {token_id} of type {type(SCREAMING_SNAKE_CASE					)}"""					)

									lowercase__					:   List[Any]													=					False
									lowercase__					:   Any													=					False
									lowercase__					:   Dict													=					False

									if self.does_advance(SCREAMING_SNAKE_CASE					):
													self.current_seq.append(SCREAMING_SNAKE_CASE					)
													lowercase__					:   str													=					True
									else:
													lowercase__					:   str													=					True
													self.reset()

									lowercase__					:   Optional[int]													=					self.trie.reached_leaf(self.current_seq					)
									lowercase__					:   Dict													=					completed

									return stepped, completed, reset







					def 			snake_case					(							self :     Dict					):
									lowercase__					:   List[str]													=					False
									lowercase__					:   Tuple													=					[]







					def 			snake_case					(							self :     Dict					):
									if self.completed:
													# since this can be completed without reaching max height
													return 0
									else:
													return self.seqlen - len(self.current_seq					)







					def 			snake_case					(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     List[Any]=False					):
									lowercase__					:   Dict													=					DisjunctiveConstraint(self.token_ids					)

									if stateful:
													lowercase__					:   Any													=					self.seqlen
													lowercase__					:   Union[str, Any]													=					self.current_seq
													lowercase__					:   Dict													=					self.completed

									return new_constraint






class 				snake_case__:

					"""simple docstring"""






					def __init__(							self :     int				,       SCREAMING_SNAKE_CASE :     List[Constraint]					):
									lowercase__					:   Any													=					constraints

									# max # of steps required to fulfill a given constraint
									lowercase__					:   List[str]													=					max([c.seqlen for c in constraints]					)
									lowercase__					:   int													=					len(SCREAMING_SNAKE_CASE					)
									lowercase__					:   Optional[Any]													=					False

									self.init_state()







					def 			snake_case					(							self :     Optional[Any]					):
									lowercase__					:   Optional[int]													=					[]
									lowercase__					:   Tuple													=					None
									lowercase__					:   Optional[int]													=					[constraint.copy(stateful=SCREAMING_SNAKE_CASE					) for constraint in self.constraints]







					def 			snake_case					(							self :     Optional[Any]					):
									lowercase__					:   List[Any]													=					0
									if self.inprogress_constraint:
													# extra points for having a constraint mid-fulfilled
													add += self.max_seqlen - self.inprogress_constraint.remaining()

									return (len(self.complete_constraints					) * self.max_seqlen) + add







					def 			snake_case					(							self :     str					):
									lowercase__					:   Any													=					[]
									if self.inprogress_constraint is None:
													for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
																	lowercase__					:   Optional[int]													=					constraint.advance()
																	if isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
																					token_list.append(SCREAMING_SNAKE_CASE					)
																	elif isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
																					token_list.extend(SCREAMING_SNAKE_CASE					)
									else:
													lowercase__					:   Tuple													=					self.inprogress_constraint.advance()
													if isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
																	token_list.append(SCREAMING_SNAKE_CASE					)
													elif isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
																	token_list.extend(SCREAMING_SNAKE_CASE					)

									if len(SCREAMING_SNAKE_CASE					) == 0:
													return None
									else:
													return token_list







					def 			snake_case					(							self :     Dict				,       SCREAMING_SNAKE_CASE :     Optional[List[int]]					):
									self.init_state()

									if token_ids is not None:
													for token in token_ids:
																	# completes or steps **one** constraint
																	lowercase__							,							lowercase__					:   Optional[int]													=					self.add(SCREAMING_SNAKE_CASE					)

																	# the entire list of constraints are fulfilled
																	if self.completed:
																					break







					def 			snake_case					(							self :     Optional[int]				,       SCREAMING_SNAKE_CASE :     int					):
									if not isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
													raise ValueError(f"""`token_id` should be an `int`, but is `{token_id}`."""					)

									lowercase__							,							lowercase__					:   int													=					False, False

									if self.completed:
													lowercase__					:   Optional[int]													=					True
													lowercase__					:   List[Any]													=					False
													return complete, stepped

									if self.inprogress_constraint is not None:
													# In the middle of fulfilling a constraint. If the `token_id` *does* makes an incremental progress to current
													# job, simply update the state

													lowercase__							,							lowercase__							,							lowercase__					:   Dict													=					self.inprogress_constraint.update(SCREAMING_SNAKE_CASE					)
													if reset:
																	# 1. If the next token breaks the progress, then we must restart.
																	#     e.g. constraint = "I love pies" and sequence so far is "I love" but `token_id` == "books".

																	#     But that doesn't mean we self.init_state(), since we only reset the state for this particular
																	#     constraint, not the full list of constraints.

																	self.pending_constraints.append(self.inprogress_constraint.copy(stateful=SCREAMING_SNAKE_CASE					)					)
																	lowercase__					:   Tuple													=					None

													if complete:
																	# 2. If the next token completes the constraint, move it to completed list, set
																	#     inprogress to None. If there are no pending constraints either, then this full list of constraints
																	#     is complete.

																	self.complete_constraints.append(self.inprogress_constraint					)
																	lowercase__					:   Optional[int]													=					None

																	if len(self.pending_constraints					) == 0:
																					# we're done!
																					lowercase__					:   Union[str, Any]													=					True

									else:
													# Not in the middle of fulfilling a constraint. So does this `token_id` helps us step towards any of our list
													# of constraints?

													for cidx, pending_constraint in enumerate(self.pending_constraints					):
																	if pending_constraint.does_advance(SCREAMING_SNAKE_CASE					):
																					lowercase__							,							lowercase__							,							lowercase__					:   Any													=					pending_constraint.update(SCREAMING_SNAKE_CASE					)

																					if not stepped:
																									raise Exception(
																									    "`constraint.update(token_id)` is not yielding incremental progress, "
																									    "even though `constraint.does_advance(token_id)` is true."					)

																					if complete:
																									self.complete_constraints.append(SCREAMING_SNAKE_CASE					)
																									lowercase__					:   int													=					None

																					if not complete and stepped:
																									lowercase__					:   Dict													=					pending_constraint

																					if complete or stepped:
																									# If we made any progress at all, then it's at least not a "pending constraint".

																									lowercase__					:   str													=					(
																									    self.pending_constraints[:cidx] + self.pending_constraints[cidx + 1 :]
																									)

																									if len(self.pending_constraints					) == 0 and self.inprogress_constraint is None:
																													# If there's no longer any pending after this and no inprogress either, then we must be
																													# complete.

																													lowercase__					:   List[str]													=					True

																									break  # prevent accidentally stepping through multiple constraints with just one token.

									return complete, stepped







					def 			snake_case					(							self :     str				,       SCREAMING_SNAKE_CASE :     Optional[Any]=True					):
									lowercase__					:   Dict													=					ConstraintListState(self.constraints					)  # we actually never though self.constraints objects
									# throughout this process. So it's at initialization state.

									if stateful:
													lowercase__					:   Optional[int]													=					[
													    constraint.copy(stateful=SCREAMING_SNAKE_CASE					) for constraint in self.complete_constraints
													]
													if self.inprogress_constraint is not None:
																	lowercase__					:   Dict													=					self.inprogress_constraint.copy(stateful=SCREAMING_SNAKE_CASE					)
													lowercase__					:   Optional[int]													=					[constraint.copy() for constraint in self.pending_constraints]

									return new_state









from __future__ import annotations

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

class 				snake_case__:

					"""simple docstring"""






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







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







					def __str__(							self :     int					):
									return "(" + ",".join(map(SCREAMING_SNAKE_CASE				,       self.__components					)					) + ")"







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







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







					@overload
					def __mul__(							self :     int				,       SCREAMING_SNAKE_CASE :     float					):
									...







					@overload
					def __mul__(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     Vector					):
									...







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







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







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







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







					def 			snake_case					(							self :     Any					):
									if len(self.__components					) == 0:
													raise Exception("Vector is empty"					)
									lowercase__					:   Union[str, Any]													=					[c**2 for c in self.__components]
									return math.sqrt(sum(SCREAMING_SNAKE_CASE					)					)







					def 			snake_case					(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     Vector				,       SCREAMING_SNAKE_CASE :     bool = False					):
									lowercase__					:   Optional[Any]													=					self * other
									lowercase__					:   Union[str, Any]													=					self.euclidean_length() * other.euclidean_length()
									if deg:
													return math.degrees(math.acos(num / den					)					)
									else:
													return math.acos(num / den					)






def  __lowerCamelCase (       lowerCamelCase__						):

				"""simple docstring"""


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


def  __lowerCamelCase (       lowerCamelCase__					,			lowerCamelCase__						):

				"""simple docstring"""


				assert isinstance(lowerCamelCase__					,			lowerCamelCase__						) and (isinstance(lowerCamelCase__					,			lowerCamelCase__						))
				lowercase__					:   Tuple													=					[0] * dimension
				lowercase__					:   Union[str, Any]													=					1
				return Vector(lowerCamelCase__						)


def  __lowerCamelCase (       lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__						):

				"""simple docstring"""


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


def  __lowerCamelCase (       lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__						):

				"""simple docstring"""


				random.seed(lowerCamelCase__						)
				lowercase__					:   Optional[Any]													=					[random.randint(lowerCamelCase__					,			lowerCamelCase__						) for _ in range(lowerCamelCase__						)]
				return Vector(lowerCamelCase__						)

class 				snake_case__:

					"""simple docstring"""






					def __init__(							self :     Optional[Any]				,       SCREAMING_SNAKE_CASE :     list[list[float]]				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   List[str]													=					matrix
									lowercase__					:   int													=					w
									lowercase__					:   str													=					h







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







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







					@overload
					def __mul__(							self :     Any				,       SCREAMING_SNAKE_CASE :     float					):
									...







					@overload
					def __mul__(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     Vector					):
									...







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







					def 			snake_case					(							self :     Union[str, Any]					):
									return self.__height







					def 			snake_case					(							self :     Optional[Any]					):
									return self.__width







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







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







					def 			snake_case					(							self :     Dict				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     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(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					)
									else:
													raise Exception("Indices out of bounds"					)







					def 			snake_case					(							self :     List[str]					):
									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__					:   Dict													=					[
													    self.__matrix[0][y] * self.cofactor(0				,       SCREAMING_SNAKE_CASE					) for y in range(self.__width					)
													]
													return sum(SCREAMING_SNAKE_CASE					)






def  __lowerCamelCase (       lowerCamelCase__						):

				"""simple docstring"""


				lowercase__					:   list[list[float]]													=					[[0] * n for _ in range(lowerCamelCase__						)]
				return Matrix(lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__						)


def  __lowerCamelCase (       lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__						):

				"""simple docstring"""


				random.seed(lowerCamelCase__						)
				lowercase__					:   list[list[float]]													=					[
				    [random.randint(lowerCamelCase__					,			lowerCamelCase__						) for _ in range(lowerCamelCase__						)] for _ in range(lowerCamelCase__						)
				]
				return Matrix(lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__						)




