





from __future__ import annotations

from collections.abc import MutableSequence

class      A       :



      def __init__(	self:						List[Any]		,  _lowerCAmelCase:						int		,  _lowerCAmelCase:						MutableSequence[float]       )						->    None:
         '''simple docstring'''

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

         UpperCAmelCase_											=list(_lowerCAmelCase       )
         UpperCAmelCase_											=degree



      def __add__(	self:						Tuple		,  _lowerCAmelCase:						Polynomial       )						->    Polynomial:
         '''simple docstring'''

         if self.degree > polynomial_a.degree:
            UpperCAmelCase_											=self.coefficients[:]
            for i in range(polynomial_a.degree + 1       ):
               coefficients[i] += polynomial_a.coefficients[i]
            return Polynomial(self.degree		,  _lowerCAmelCase       )
         else:
            UpperCAmelCase_											=polynomial_a.coefficients[:]
            for i in range(self.degree + 1       ):
               coefficients[i] += self.coefficients[i]
            return Polynomial(polynomial_a.degree		,  _lowerCAmelCase       )



      def __sub__(	self:						List[Any]		,  _lowerCAmelCase:						Polynomial       )						->    Polynomial:
         '''simple docstring'''

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



      def __neg__(	self:						List[Any]       )						->    Polynomial:
         '''simple docstring'''

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



      def __mul__(	self:						Any		,  _lowerCAmelCase:						Polynomial       )						->    Polynomial:
         '''simple docstring'''

         UpperCAmelCase_											=[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		,  _lowerCAmelCase       )



      def 	lowerCAmelCase__    (	self:						Tuple		,  _lowerCAmelCase:						int | float       )						->    int | float:
         '''simple docstring'''

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



      def __str__(	self:						Dict       )						->    str:
         '''simple docstring'''

         UpperCAmelCase_											=""
         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(_lowerCAmelCase       )

         return polynomial



      def __repr__(	self:						List[str]       )						->    str:
         '''simple docstring'''

         return self.__str__()



      def 	lowerCAmelCase__    (	self:						List[str]       )						->    Polynomial:
         '''simple docstring'''

         UpperCAmelCase_											=[0] * self.degree
         for i in range(self.degree       ):
            UpperCAmelCase_											=self.coefficients[i + 1] * (i + 1)
         return Polynomial(self.degree - 1		,  _lowerCAmelCase       )



      def 	lowerCAmelCase__    (	self:						Tuple		,  _lowerCAmelCase:						int | float = 0       )						->    Polynomial:
         '''simple docstring'''

         UpperCAmelCase_											=[0] * (self.degree + 2)
         UpperCAmelCase_											=constant
         for i in range(self.degree + 1       ):
            UpperCAmelCase_											=self.coefficients[i] / (i + 1)
         return Polynomial(self.degree + 1		,  _lowerCAmelCase       )



      def __eq__(	self:						int		,  _lowerCAmelCase:						object       )						->    bool:
         '''simple docstring'''

         if not isinstance(_lowerCAmelCase		,  _lowerCAmelCase       ):
            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:						Optional[Any]		,  _lowerCAmelCase:						object       )						->    bool:
         '''simple docstring'''

         return not self.__eq__(_lowerCAmelCase       )











__lowercase  :   Optional[Any]						      =[
    (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     a__ (					lowercase__  ):






   '''simple docstring'''






   UpperCAmelCase_											={"I": 1, "V": 5, "X": 1_0, "L": 5_0, "C": 1_0_0, "D": 5_0_0, "M": 1_0_0_0}
   UpperCAmelCase_											=0
   UpperCAmelCase_											=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     a__ (					lowercase__  ):






   '''simple docstring'''






   UpperCAmelCase_											=[]
   for arabic, roman in ROMAN:
      ((UpperCAmelCase_)						,       (UpperCAmelCase_))											=divmod(lowercase__  ,    lowercase__  )
      result.append(roman * factor  )
      if number == 0:
         break
   return "".join(lowercase__  )


if __name__ == "__main__":
     import doctest

     doctest.testmod()




