

from collections.abc import Callable

lowercase     :       Optional[Any]        =       Callable[[float], float]  # type alias for a real -> real function







def  UpperCAmelCase_   (_lowerCAmelCase :		RealFunc     ,			_lowerCAmelCase :		RealFunc     ,			_lowerCAmelCase :		int     ,			):
			__UpperCamelCase    :    Any								=      float(_lowerCAmelCase		)
			while True:
						try:
									__UpperCamelCase    :    List[Any]								=      prev_guess - function(_lowerCAmelCase		) / derivative(_lowerCAmelCase		)
						except ZeroDivisionError:
									raise ZeroDivisionError("Could not find root"		) from None
						if abs(prev_guess - next_guess		) < 10**-5:
									return next_guess
						__UpperCamelCase    :    Tuple								=      next_guess







def  UpperCAmelCase_   (_lowerCAmelCase :		float		):
			return (x**3) - (2 * x) - 5







def  UpperCAmelCase_   (_lowerCAmelCase :		float		):
			return 3 * (x**2) - 2


if __name__ == "__main__":
					print(newton(f, fa, 3))


from __future__ import annotations







def  UpperCAmelCase_   (_lowerCAmelCase :		int     ,			_lowerCAmelCase :		list[int]     ,			_lowerCAmelCase :		list[int]     ,			_lowerCAmelCase :		int		):

			# Base Case
			if counter == 0 or capacity == 0:
						return 0

			# If weight of the nth item is more than Knapsack of capacity,
			#   then this item cannot be included in the optimal solution,
			# else return the maximum of two cases:
			#   (1) nth item included
			#   (2) not included
			if weights[counter - 1] > capacity:
						return knapsack(_lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			counter - 1		)
			else:
						__UpperCamelCase    :    Tuple								=      capacity - weights[counter - 1]
						__UpperCamelCase    :    List[str]								=      values[counter - 1] + knapsack(
						    _lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			counter - 1		)
						__UpperCamelCase    :    Dict								=      knapsack(_lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			counter - 1		)
						return max(_lowerCAmelCase     ,			_lowerCAmelCase		)


if __name__ == "__main__":
					import doctest

					doctest.testmod()