



from __future__ import annotations

from collections.abc import MutableSequence





class 					__lowerCAmelCase :




				def __init__(							self						,				_snake_case						,				_snake_case		):



									"""simple docstring"""





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

									_lowerCAmelCase						=    list(_snake_case		)
									_lowerCAmelCase						=    degree




				def __add__(							self						,				_snake_case		):



									"""simple docstring"""





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




				def __sub__(							self						,				_snake_case		):



									"""simple docstring"""





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




				def __neg__(							self		):



									"""simple docstring"""





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




				def __mul__(							self						,				_snake_case		):



									"""simple docstring"""





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




				def 							snake_case   (							self						,				_snake_case		):



									"""simple docstring"""





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




				def __str__(							self		):



									"""simple docstring"""





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

									return polynomial




				def __repr__(							self		):



									"""simple docstring"""





									return self.__str__()




				def 							snake_case   (							self		):



									"""simple docstring"""





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




				def 							snake_case   (							self						,				_snake_case = 0		):



									"""simple docstring"""





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




				def __eq__(							self						,				_snake_case		):



									"""simple docstring"""





									if not isinstance(_snake_case						,				_snake_case		):
														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						,				_snake_case		):



									"""simple docstring"""





									return not self.__eq__(_snake_case		)







'''simple docstring'''
def 					a__       (					lowerCAmelCase__						)    ->	int:
    if a < 0:
        raise ValueError('''Input value must be a positive integer'''						)
    elif isinstance(lowerCAmelCase__  ,					lowerCAmelCase__						):
        raise TypeError('''Input value must be a \'int\' type'''						)
    return bin(lowerCAmelCase__						).count('''1'''						)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
