'''simple docstring'''




from __future__ import annotations

from collections.abc import Callable

__UpperCAmelCase					=list[list[float | int]]






def __lowerCAmelCase					(				UpperCamelCase__							,    UpperCamelCase__							)      ->       Matrix:
    __lowerCamelCase            =    len(UpperCamelCase__							)
    __lowerCamelCase            =    [[0 for _ in range(size + 1							)] for _ in range(UpperCamelCase__							)]
    __lowerCamelCase            =    42
    __lowerCamelCase            =    42
    __lowerCamelCase            =    42
    __lowerCamelCase            =    42
    __lowerCamelCase            =    42
    __lowerCamelCase            =    42

    for row in range(UpperCamelCase__							):
        for col in range(UpperCamelCase__							):
            __lowerCamelCase            =    matrix[row][col]

        __lowerCamelCase            =    vector[row][0]

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

        for rowa in range(row + 1							,    UpperCamelCase__							):
            __lowerCamelCase            =    augmented[rowa][col] / augmented[row][col]
            __lowerCamelCase            =    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							,    UpperCamelCase__							):
        for row in range(UpperCamelCase__							):
            __lowerCamelCase            =    augmented[row][col] / augmented[col][col]
            for cola in range(UpperCamelCase__							,    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]							,    10							)] for row in range(UpperCamelCase__							)
    ]






def __lowerCAmelCase					(				UpperCamelCase__							)      ->       Callable[[int], int]:
    __lowerCamelCase            =    len(UpperCamelCase__							)
    __lowerCamelCase            =    [[0 for _ in range(UpperCamelCase__							)] for _ in range(UpperCamelCase__							)]
    __lowerCamelCase            =    [[0] for _ in range(UpperCamelCase__							)]
    __lowerCamelCase            =    42
    __lowerCamelCase            =    42
    __lowerCamelCase            =    42
    __lowerCamelCase            =    42

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

    __lowerCamelCase            =    solve(UpperCamelCase__							,    UpperCamelCase__							)

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

    return interpolated_func






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






def __lowerCAmelCase					(				UpperCamelCase__ = question_function							,    UpperCamelCase__ = 10							)      ->       int:
    __lowerCamelCase            =    [func(UpperCamelCase__							) for x_val in range(1							,    order + 1							)]

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

    __lowerCamelCase            =    0
    __lowerCamelCase            =    42
    __lowerCamelCase            =    42

    for poly in polynomials:
        __lowerCamelCase            =    1
        while func(UpperCamelCase__							) == poly(UpperCamelCase__							):
            x_val += 1

        ret += poly(UpperCamelCase__							)

    return ret


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

'''simple docstring'''




def __lowerCAmelCase					(				UpperCamelCase__							)      ->       bool:
    if not isinstance(UpperCamelCase__							,    UpperCamelCase__							):
        raise ValueError('''Input series is not valid, valid series - [2, 4, 6]'''							)
    if len(UpperCamelCase__							) == 0:
        raise ValueError('''Input list must be a non empty list'''							)
    if len(UpperCamelCase__							) == 1:
        return True
    __lowerCamelCase            =    series[1] - series[0]
    for index in range(len(UpperCamelCase__							) - 1							):
        if series[index + 1] - series[index] != common_diff:
            return False
    return True






def __lowerCAmelCase					(				UpperCamelCase__							)      ->       float:
    if not isinstance(UpperCamelCase__							,    UpperCamelCase__							):
        raise ValueError('''Input series is not valid, valid series - [2, 4, 6]'''							)
    if len(UpperCamelCase__							) == 0:
        raise ValueError('''Input list must be a non empty list'''							)
    __lowerCamelCase            =    0
    for val in series:
        answer += val
    return answer / len(UpperCamelCase__							)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
