





from __future__ import annotations

from collections.abc import Callable
from typing import Any, Generic, TypeVar

UpperCamelCase__											= TypeVar("T")

class        __SCREAMING_SNAKE_CASE					(     Generic[T]       ):






							def __init__(						self  , __lowerCAmelCase  , __lowerCAmelCase  ):
														UpperCamelCase__				     =			None

														UpperCamelCase__				     =			len(__lowerCAmelCase  )
														UpperCamelCase__				     =			[any_type for _ in range(self.N  )] + arr
														UpperCamelCase__				     =			fnc
														self.build()






							def 				_lowerCamelCase		(						self  ):
														for p in range(self.N - 1  , 0  , -1  ):
																					UpperCamelCase__				     =			self.fn(self.st[p * 2]  , self.st[p * 2 + 1]  )






							def 				_lowerCamelCase		(						self  , __lowerCAmelCase  , __lowerCAmelCase  ):
														p += self.N
														UpperCamelCase__				     =			v
														while p > 1:
																					UpperCamelCase__				     =			p // 2
																					UpperCamelCase__				     =			self.fn(self.st[p * 2]  , self.st[p * 2 + 1]  )







							def 				_lowerCamelCase		(						self  , __lowerCAmelCase  , __lowerCAmelCase  ):  # noqa: E741
														UpperCamelCase__     ,     UpperCamelCase__				     =			l + self.N, r + self.N

														UpperCamelCase__				     =			None
														while l <= r:
																					if l % 2 == 1:
																												UpperCamelCase__				     =			self.st[l] if res is None else self.fn(__lowerCAmelCase  , self.st[l]  )
																					if r % 2 == 0:
																												UpperCamelCase__				     =			self.st[r] if res is None else self.fn(__lowerCAmelCase  , self.st[r]  )
																					UpperCamelCase__     ,     UpperCamelCase__				     =			(l + 1) // 2, (r - 1) // 2
														return res


if __name__ == "__main__":
					from functools import reduce

					UpperCamelCase__											= [1, 10, -2, 9, -3, 8, 4, -7, 5, 6, 11, -12]

					UpperCamelCase__											= {
					    0: 7,
					    1: 2,
					    2: 6,
					    3: -14,
					    4: 5,
					    5: 4,
					    6: 7,
					    7: -10,
					    8: 9,
					    9: 10,
					    10: 12,
					    11: 1,
					}

					UpperCamelCase__											= SegmentTree(test_array, min)
					UpperCamelCase__											= SegmentTree(test_array, max)
					UpperCamelCase__											= SegmentTree(test_array, lambda a, b: a + b)





					def     _UpperCamelCase     ():






												"""simple docstring"""





												for i in range(len(a__       )       ):
																			for j in range(a__   ,			len(a__       )       ):
																										UpperCamelCase__				     =			reduce(a__   ,			test_array[i : j + 1]       )
																										UpperCamelCase__				     =			reduce(a__   ,			test_array[i : j + 1]       )
																										UpperCamelCase__				     =			reduce(lambda a__   ,			a__       : a + b   ,			test_array[i : j + 1]       )
																										assert min_range == min_segment_tree.query(a__   ,			a__       )
																										assert max_range == max_segment_tree.query(a__   ,			a__       )
																										assert sum_range == sum_segment_tree.query(a__   ,			a__       )

					test_all_segments()

					for index, value in test_updates.items():
										UpperCamelCase__											= value
										min_segment_tree.update(index, value)
										max_segment_tree.update(index, value)
										sum_segment_tree.update(index, value)
										test_all_segments()











from sympy import diff, lambdify, symbols
from sympy.functions import *  # noqa: F403





def     _UpperCamelCase     (a__   :str   ,			a__   :complex   ,			a__   :str = "x"   ,			a__   :float = 10**-10   ,			a__   :int = 1   ,			):






							"""simple docstring"""





							UpperCamelCase__				     =			symbols(a__       )
							UpperCamelCase__				     =			lambdify(a__   ,			a__       )
							UpperCamelCase__				     =			lambdify(a__   ,			diff(a__   ,			a__       )       )

							UpperCamelCase__				     =			starting_point

							while True:
														if diff_function(a__       ) != 0:
																					UpperCamelCase__				     =			prev_guess - multiplicity * func(a__       ) / diff_function(
																					    a__       )
														else:
																					raise ZeroDivisionError("""Could not find root"""       ) from None

														# Precision is checked by comparing the difference of consecutive guesses
														if abs(next_guess - prev_guess       ) < precision:
																					return next_guess

														UpperCamelCase__				     =			next_guess


# Let's Execute
if __name__ == "__main__":
					# Find root of trigonometric function
					# Find value of pi
					print(f"""The root of sin(x) = 0 is {newton_raphson('sin(x)', 2)}""")

					# Find root of polynomial
					# Find fourth Root of 5
					print(f"""The root of x**4 - 5 = 0 is {newton_raphson('x**4 -5', 0.4 +5J)}""")

					# Find value of e
					print(
					    "The root of log(y) - 1 = 0 is ",
					    f"""{newton_raphson('log(y) - 1', 2, variable='y')}""",
					)

					# Exponential Roots
					print(
					    "The root of exp(x) - 1 = 0 is",
					    f"""{newton_raphson('exp(x) - 1', 10, precision=0.0_05)}""",
					)

					# Find root of cos(x)
					print(f"""The root of cos(x) = 0 is {newton_raphson('cos(x)', 0)}""")




