


from __future__ import annotations

from collections.abc import Callable

snake_case							: Optional[Any]      =   list[list[float | int]]






def 							__lowercase     (				__lowerCAmelCase							:       Matrix      ,					__lowerCAmelCase							:       Matrix     ):
							a__    =  len(__lowerCAmelCase     )
							a__    =  [[0 for _ in range(size + 1     )] for _ in range(__lowerCAmelCase     )]
							a__    =  42
							a__    =  42
							a__    =  42
							a__    =  42
							a__    =  42
							a__    =  42

							for row in range(__lowerCAmelCase     ):
														for col in range(__lowerCAmelCase     ):
																					a__    =  matrix[row][col]

														a__    =  vector[row][0]

							a__    =  0
							a__    =  0
							while row < size and col < size:
														# pivoting
														a__    =  max((abs(augmented[rowa][col]     ), rowa) for rowa in range(__lowerCAmelCase      ,					__lowerCAmelCase     )     )[
														    1
														]
														if augmented[pivot_row][col] == 0:
																					col += 1
																					continue
														else:
																					a__   ,      a__    =  augmented[pivot_row], augmented[row]

														for rowa in range(row + 1      ,					__lowerCAmelCase     ):
																					a__    =  augmented[rowa][col] / augmented[row][col]
																					a__    =  0
																					for cola in range(col + 1      ,					size + 1     ):
																												augmented[rowa][cola] -= augmented[row][cola] * ratio

														row += 1
														col += 1

							# back substitution
							for col in range(1      ,					__lowerCAmelCase     ):
														for row in range(__lowerCAmelCase     ):
																					a__    =  augmented[row][col] / augmented[col][col]
																					for cola in range(__lowerCAmelCase      ,					size + 1     ):
																												augmented[row][cola] -= augmented[col][cola] * ratio

    # round to get rid of numbers like 2.000000000000004
							return [
							    [round(augmented[row][size] / augmented[row][row]      ,					1_0     )] for row in range(__lowerCAmelCase     )
							]






def 							__lowercase     (				__lowerCAmelCase							:       list[int]     ):
							a__    =  len(__lowerCAmelCase     )
							a__    =  [[0 for _ in range(__lowerCAmelCase     )] for _ in range(__lowerCAmelCase     )]
							a__    =  [[0] for _ in range(__lowerCAmelCase     )]
							a__    =  42
							a__    =  42
							a__    =  42
							a__    =  42

							for x_val, y_val in enumerate(__lowerCAmelCase     ):
														for col in range(__lowerCAmelCase     ):
																					a__    =  (x_val + 1) ** (size - col - 1)
														a__    =  y_val

							a__    =  solve(__lowerCAmelCase      ,					__lowerCAmelCase     )

							def interpolated_func(__lowerCAmelCase							:       int     ) -> int:
														return sum(
														    round(coeffs[x_val][0]     ) * (var ** (size - x_val - 1))
														    for x_val in range(__lowerCAmelCase     )     )

							return interpolated_func






def 							__lowercase     (				__lowerCAmelCase							:       int     ):
							return (
							    1
							    - variable
							    + variable**2
							    - variable**3
							    + variable**4
							    - variable**5
							    + variable**6
							    - variable**7
							    + variable**8
							    - variable**9
							    + variable**1_0
							)






def 							__lowercase     (				__lowerCAmelCase							:       Callable[[int], int] = question_function      ,					__lowerCAmelCase							:       int = 1_0     ):
							a__    =  [func(__lowerCAmelCase     ) for x_val in range(1      ,					order + 1     )]

							a__    =  [
							    interpolate(data_points[:max_coeff]     ) for max_coeff in range(1      ,					order + 1     )
							]

							a__    =  0
							a__    =  42
							a__    =  42

							for poly in polynomials:
														a__    =  1
														while func(__lowerCAmelCase     ) == poly(__lowerCAmelCase     ):
																					x_val += 1

														ret += poly(__lowerCAmelCase     )

							return ret


if __name__ == "__main__":
						print(f"""{solution() = }""")








def 							__lowercase     (				__lowerCAmelCase							:       int     ):

							if length <= 0 or not isinstance(__lowerCAmelCase      ,					__lowerCAmelCase     ):
														raise ValueError('Length must be a positive integer.'     )
							return [n * (2 * n - 1) for n in range(__lowerCAmelCase     )]


if __name__ == "__main__":
						print(hexagonal_numbers(length=5))
						print(hexagonal_numbers(length=10))




