



from __future__ import annotations

from collections.abc import MutableSequence

class        snake_case__    :







						"""simple docstring"""




						def __init__(       self ,       __lowercase ,       __lowercase  ) ->				None:
									"""simple docstring"""




									if len(__lowercase  ) != degree + 1:
												raise ValueError(
												    """The number of coefficients should be equal to the degree + 1."""  )

									a__       :						list[float]							=  list(__lowercase  )
									a__       :						Optional[int]							=  degree

						def __add__(       self ,       __lowercase  ) ->				Polynomial:
									"""simple docstring"""




									if self.degree > polynomial_a.degree:
												a__       :						List[str]							=  self.coefficients[:]
												for i in range(polynomial_a.degree + 1  ):
															coefficients[i] += polynomial_a.coefficients[i]
												return Polynomial(self.degree ,       __lowercase  )
									else:
												a__       :						int							=  polynomial_a.coefficients[:]
												for i in range(self.degree + 1  ):
															coefficients[i] += self.coefficients[i]
												return Polynomial(polynomial_a.degree ,       __lowercase  )

						def __sub__(       self ,       __lowercase  ) ->				Polynomial:
									"""simple docstring"""




									return self + polynomial_a * Polynomial(0 ,       [-1]  )

						def __neg__(       self  ) ->				Polynomial:
									"""simple docstring"""




									return Polynomial(self.degree ,       [-c for c in self.coefficients]  )

						def __mul__(       self ,       __lowercase  ) ->				Polynomial:
									"""simple docstring"""




									a__       :						list[float]							=  [0] * (self.degree + polynomial_a.degree + 1)
									for i in range(self.degree + 1  ):
												for j in range(polynomial_a.degree + 1  ):
															coefficients[i + j] += (
															    self.coefficients[i] * polynomial_a.coefficients[j]
															)

									return Polynomial(self.degree + polynomial_a.degree ,       __lowercase  )

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase  ) ->				int | float:
									"""simple docstring"""




									a__       :						int | float							=  0
									for i in range(self.degree + 1  ):
												result += self.coefficients[i] * (substitution**i)
									return result

						def __str__(       self  ) ->				str:
									"""simple docstring"""




									a__       :						Union[str, Any]							=  """"""
									for i in range(self.degree ,       -1 ,       -1  ):
												if self.coefficients[i] == 0:
															continue
												elif self.coefficients[i] > 0:
															if polynomial:
																		polynomial += " + "
												else:
															polynomial += " - "

												if i == 0:
															polynomial += str(abs(self.coefficients[i]  )  )
												elif i == 1:
															polynomial += str(abs(self.coefficients[i]  )  ) + "x"
												else:
															polynomial += str(abs(self.coefficients[i]  )  ) + "x^" + str(__lowercase  )

									return polynomial

						def __repr__(       self  ) ->				str:
									"""simple docstring"""




									return self.__str__()

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Polynomial:
									"""simple docstring"""




									a__       :						list[float]							=  [0] * self.degree
									for i in range(self.degree  ):
												a__       :						Tuple							=  self.coefficients[i + 1] * (i + 1)
									return Polynomial(self.degree - 1 ,       __lowercase  )

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase = 0  ) ->				Polynomial:
									"""simple docstring"""




									a__       :						list[float]							=  [0] * (self.degree + 2)
									a__       :						int							=  constant
									for i in range(self.degree + 1  ):
												a__       :						Union[str, Any]							=  self.coefficients[i] / (i + 1)
									return Polynomial(self.degree + 1 ,       __lowercase  )

						def __eq__(       self ,       __lowercase  ) ->				bool:
									"""simple docstring"""




									if not isinstance(__lowercase ,       __lowercase  ):
												return False

									if self.degree != polynomial_a.degree:
												return False

									for i in range(self.degree + 1  ):
												if self.coefficients[i] != polynomial_a.coefficients[i]:
															return False

									return True

						def __ne__(       self ,       __lowercase  ) ->				bool:
									"""simple docstring"""




									return not self.__eq__(__lowercase  )









import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
		import ctypes
		import msvcrt  # noqa

		class        snake_case__    (ctypes.Structure		):







								"""simple docstring"""




								__lowerCAmelCase					:Dict      =					[("size", ctypes.c_int), ("visible", ctypes.c_byte)]

def      lowerCAmelCase_					(  )							->	List[Any]:







			"""simple docstring"""
			if os.name == "nt":
						a__       :						int							=  CursorInfo()
						a__       :						Union[str, Any]							=  ctypes.windll.kernelaa.GetStdHandle(-11)
						ctypes.windll.kernelaa.GetConsoleCursorInfo(_lowercase						,       ctypes.byref(_lowercase))
						a__       :						List[str]							=  False
						ctypes.windll.kernelaa.SetConsoleCursorInfo(_lowercase						,       ctypes.byref(_lowercase))
			elif os.name == "posix":
						sys.stdout.write("""\033[?25l""")
						sys.stdout.flush()

def      lowerCAmelCase_					(  )							->	Optional[Any]:







			"""simple docstring"""
			if os.name == "nt":
						a__       :						List[Any]							=  CursorInfo()
						a__       :						Optional[int]							=  ctypes.windll.kernelaa.GetStdHandle(-11)
						ctypes.windll.kernelaa.GetConsoleCursorInfo(_lowercase						,       ctypes.byref(_lowercase))
						a__       :						Dict							=  True
						ctypes.windll.kernelaa.SetConsoleCursorInfo(_lowercase						,       ctypes.byref(_lowercase))
			elif os.name == "posix":
						sys.stdout.write("""\033[?25h""")
						sys.stdout.flush()





@contextmanager
def      lowerCAmelCase_					(  )							->	Any:







			"""simple docstring"""
			try:
						hide_cursor()
						yield
			finally:
						show_cursor()




