





from __future__ import annotations

from collections.abc import MutableSequence


class 						lowerCamelCase       :







       """simple docstring"""




       def __init__( self     :					Union[str, Any],			_UpperCAmelCase     :					int,			_UpperCAmelCase     :					MutableSequence[float]						)				->			Optional[Any]:





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

              SCREAMING_SNAKE_CASE__       :      List[Any]     =						list(__lowerCAmelCase						)
              SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						degree






       def __add__( self     :					List[str],			_UpperCAmelCase     :					Polynomial						)				->			str:





              """simple docstring"""

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






       def __sub__( self     :					Union[str, Any],			_UpperCAmelCase     :					Polynomial						)				->			List[Any]:





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






       def __neg__( self     :					Dict						)				->			int:





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






       def __mul__( self     :					Any,			_UpperCAmelCase     :					Polynomial						)				->			str:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						[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  A_     ( self     :					str,			_UpperCAmelCase     :					int | float						)				->			Optional[int]:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      Optional[int]     =						0
              for i in range(self.degree + 1						):
                     result += self.coefficients[i] * (substitution**i)
              return result






       def __str__( self     :					Dict						)				->			str:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      Tuple     =						""
              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]						)				->			int:





              """simple docstring"""
              return self.__str__()






       def  A_     ( self     :					Union[str, Any]						)				->			str:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      Tuple     =						[0] * self.degree
              for i in range(self.degree						):
                     SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self.coefficients[i + 1] * (i + 1)
              return Polynomial(self.degree - 1,			__lowerCAmelCase						)






       def  A_     ( self     :					Any,			_UpperCAmelCase     :					int | float = 0						)				->			int:





              """simple docstring"""
              SCREAMING_SNAKE_CASE__       :      int     =						[0] * (self.degree + 2)
              SCREAMING_SNAKE_CASE__       :      Dict     =						constant
              for i in range(self.degree + 1						):
                     SCREAMING_SNAKE_CASE__       :      Optional[int]     =						self.coefficients[i] / (i + 1)
              return Polynomial(self.degree + 1,			__lowerCAmelCase						)






       def __eq__( self     :					List[str],			_UpperCAmelCase     :					object						)				->			Any:





              """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     :					Tuple,			_UpperCAmelCase     :					object						)				->			Any:





              """simple docstring"""
              return not self.__eq__(__lowerCAmelCase						)













def _a (  SCREAMING_SNAKE_CASE__      :  str       )	->    str:

							'''simple docstring'''






							if not all(char in "01" for char in bin_string       ):
														raise ValueError("Non-binary value was passed to the function"       )
							if not bin_string:
														raise ValueError("Empty string was passed to the function"       )
							SCREAMING_SNAKE_CASE__       :      List[Any]     =						""
							while len(SCREAMING_SNAKE_CASE__       ) % 3 != 0:
														SCREAMING_SNAKE_CASE__       :      str     =						"0" + bin_string
							SCREAMING_SNAKE_CASE__       :      List[Any]     =						[
							    bin_string[index : index + 3]
							    for index in range(len(SCREAMING_SNAKE_CASE__       )       )
							    if index % 3 == 0
							]
							for bin_group in bin_string_in_3_list:
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						0
														for index, val in enumerate(SCREAMING_SNAKE_CASE__       ):
																					oct_val += int(2 ** (2 - index) * int(SCREAMING_SNAKE_CASE__       )       )
														oct_string += str(SCREAMING_SNAKE_CASE__       )
							return oct_string


if __name__ == "__main__":
		from doctest import testmod

		testmod()






