



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  )











_lowercase		:				Optional[int]      		=[
    (1000, "M"),
    (900, "CM"),
    (500, "D"),
    (400, "CD"),
    (100, "C"),
    (90, "XC"),
    (50, "L"),
    (40, "XL"),
    (10, "X"),
    (9, "IX"),
    (5, "V"),
    (4, "IV"),
    (1, "I"),
]

def      lowerCAmelCase_					(  _lowercase    :       str)							->	int:







			"""simple docstring"""
			a__       :						Union[str, Any]							=  {"""I""": 1, """V""": 5, """X""": 10, """L""": 50, """C""": 100, """D""": 500, """M""": 1000}
			a__       :						List[Any]							=  0
			a__       :						Dict							=  0
			while place < len(_lowercase):
						if (place + 1 < len(_lowercase)) and (vals[roman[place]] < vals[roman[place + 1]]):
									total += vals[roman[place + 1]] - vals[roman[place]]
									place += 2
						else:
									total += vals[roman[place]]
									place += 1
			return total

def      lowerCAmelCase_					(  _lowercase    :       int)							->	str:







			"""simple docstring"""
			a__       :						Optional[Any]							=  []
			for arabic, roman in ROMAN:
						((a__)	,						(a__))       :						Optional[Any]							=  divmod(_lowercase						,       _lowercase)
						result.append(roman * factor)
						if number == 0:
									break
			return "".join(_lowercase)


if __name__ == "__main__":
		import doctest

		doctest.testmod()




