






from collections.abc import Sequence
from queue import Queue
class  lowerCAmelCase_       :




							def __init__(   self     :   str ,							SCREAMING_SNAKE_CASE_     :   List[Any] ,							SCREAMING_SNAKE_CASE_     :   str ,							SCREAMING_SNAKE_CASE_     :   List[Any] ,							SCREAMING_SNAKE_CASE_     :   Dict=None ,							SCREAMING_SNAKE_CASE_     :   int=None	):
											lowerCAmelCase__      			=						start
											lowerCAmelCase__      			=						end
											lowerCAmelCase__      			=						val
											lowerCAmelCase__      			=						(start + end) // 2
											lowerCAmelCase__      			=						left
											lowerCAmelCase__      			=						right




							def __repr__(   self     :   List[Any]	):
											return f'SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})'



class  lowerCAmelCase_       :




							def __init__(   self     :   List[Any] ,							SCREAMING_SNAKE_CASE_     :   Sequence ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]	):
											lowerCAmelCase__      			=						collection
											lowerCAmelCase__      			=						function
											if self.collection:
															lowerCAmelCase__      			=						self._build_tree(0 ,							len(SCREAMING_SNAKE_CASE_	) - 1	)




							def 						__snake_case					(   self     :   Dict ,							SCREAMING_SNAKE_CASE_     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   str	):
											self._update_tree(self.root ,							SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   Dict ,							SCREAMING_SNAKE_CASE_     :   Tuple ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]	):
											return self._query_range(self.root ,							SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   int ,							SCREAMING_SNAKE_CASE_     :   str	):
											if start == end:
															return SegmentTreeNode(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_ ,							self.collection[start]	)
											lowerCAmelCase__      			=						(start + end) // 2
											lowerCAmelCase__      			=						self._build_tree(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						self._build_tree(mid + 1 ,							SCREAMING_SNAKE_CASE_	)
											return SegmentTreeNode(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_ ,							self.fn(left.val ,							right.val	) ,							SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   str ,							SCREAMING_SNAKE_CASE_     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   int	):
											if node.start == i and node.end == i:
															lowerCAmelCase__      			=						val
															return
											if i <= node.mid:
															self._update_tree(node.left ,							SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)
											else:
															self._update_tree(node.right ,							SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						self.fn(node.left.val ,							node.right.val	)




							def 						__snake_case					(   self     :   Dict ,							SCREAMING_SNAKE_CASE_     :   Any ,							SCREAMING_SNAKE_CASE_     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   List[str]	):
											if node.start == i and node.end == j:
															return node.val

											if i <= node.mid:
															if j <= node.mid:
																			# range in left child tree
																			return self._query_range(node.left ,							SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)
															else:
																			# range in left child tree and right child tree
																			return self.fn(
																			    self._query_range(node.left ,							SCREAMING_SNAKE_CASE_ ,							node.mid	) ,							self._query_range(node.right ,							node.mid + 1 ,							SCREAMING_SNAKE_CASE_	) ,							)
											else:
															# range in right child tree
															return self._query_range(node.right ,							SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   Any	):
											if self.root is not None:
															lowerCAmelCase__      			=						Queue()
															queue.put(self.root	)
															while not queue.empty():
																			lowerCAmelCase__      			=						queue.get()
																			yield node

																			if node.left is not None:
																							queue.put(node.left	)

																			if node.right is not None:
																							queue.put(node.right	)


if __name__ == "__main__":
			import operator

			for fn in [operator.add, max, min]:
						print("*" * 50)
						_UpperCAmelCase			:		List[str]   				=    SegmentTree([2, 1, 5, 3, 4], fn)
						for node in arr.traverse():
									print(node)
						print()

						arr.update(1, 5)
						for node in arr.traverse():
									print(node)
						print()

						print(arr.query_range(3, 4))  # 7
						print(arr.query_range(2, 2))  # 5
						print(arr.query_range(1, 3))  # 13
						print()













# Imports
import numpy as np
class  lowerCAmelCase_       :




							def __init__(   self     :   Any ,							SCREAMING_SNAKE_CASE_     :   Dict=None ,							SCREAMING_SNAKE_CASE_     :   Optional[Any]=None ,							SCREAMING_SNAKE_CASE_     :   List[str]=None ,							SCREAMING_SNAKE_CASE_     :   Dict=None ,							SCREAMING_SNAKE_CASE_     :   int=None	):
											self.set_matricies(red=SCREAMING_SNAKE_CASE_ ,							green=SCREAMING_SNAKE_CASE_ ,							blue=SCREAMING_SNAKE_CASE_ ,							red_edge=SCREAMING_SNAKE_CASE_ ,							nir=SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   str ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]=None ,							SCREAMING_SNAKE_CASE_     :   Optional[int]=None ,							SCREAMING_SNAKE_CASE_     :   Optional[Any]=None ,							SCREAMING_SNAKE_CASE_     :   Optional[Any]=None ,							SCREAMING_SNAKE_CASE_     :   Dict=None	):
											if red is not None:
															lowerCAmelCase__      			=						red
											if green is not None:
															lowerCAmelCase__      			=						green
											if blue is not None:
															lowerCAmelCase__      			=						blue
											if red_edge is not None:
															lowerCAmelCase__      			=						red_edge
											if nir is not None:
															lowerCAmelCase__      			=						nir
											return True




							def 						__snake_case					(   self     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   Any="" ,							SCREAMING_SNAKE_CASE_     :   str=None ,							SCREAMING_SNAKE_CASE_     :   Optional[Any]=None ,							SCREAMING_SNAKE_CASE_     :   List[str]=None ,							SCREAMING_SNAKE_CASE_     :   Optional[Any]=None ,							SCREAMING_SNAKE_CASE_     :   Optional[Any]=None	):
											self.set_matricies(red=SCREAMING_SNAKE_CASE_ ,							green=SCREAMING_SNAKE_CASE_ ,							blue=SCREAMING_SNAKE_CASE_ ,							red_edge=SCREAMING_SNAKE_CASE_ ,							nir=SCREAMING_SNAKE_CASE_	)
											lowerCAmelCase__      			=						{
											    '''ARVI2''': self.arvaa,
											    '''CCCI''': self.ccci,
											    '''CVI''': self.cvi,
											    '''GLI''': self.gli,
											    '''NDVI''': self.ndvi,
											    '''BNDVI''': self.bndvi,
											    '''redEdgeNDVI''': self.red_edge_ndvi,
											    '''GNDVI''': self.gndvi,
											    '''GBNDVI''': self.gbndvi,
											    '''GRNDVI''': self.grndvi,
											    '''RBNDVI''': self.rbndvi,
											    '''PNDVI''': self.pndvi,
											    '''ATSAVI''': self.atsavi,
											    '''BWDRVI''': self.bwdrvi,
											    '''CIgreen''': self.ci_green,
											    '''CIrededge''': self.ci_rededge,
											    '''CI''': self.ci,
											    '''CTVI''': self.ctvi,
											    '''GDVI''': self.gdvi,
											    '''EVI''': self.evi,
											    '''GEMI''': self.gemi,
											    '''GOSAVI''': self.gosavi,
											    '''GSAVI''': self.gsavi,
											    '''Hue''': self.hue,
											    '''IVI''': self.ivi,
											    '''IPVI''': self.ipvi,
											    '''I''': self.i,
											    '''RVI''': self.rvi,
											    '''MRVI''': self.mrvi,
											    '''MSAVI''': self.m_savi,
											    '''NormG''': self.norm_g,
											    '''NormNIR''': self.norm_nir,
											    '''NormR''': self.norm_r,
											    '''NGRDI''': self.ngrdi,
											    '''RI''': self.ri,
											    '''S''': self.s,
											    '''IF''': self._if,
											    '''DVI''': self.dvi,
											    '''TVI''': self.tvi,
											    '''NDRE''': self.ndre,
											}

											try:
															return funcs[index]()
											except KeyError:
															print('''Index not in the list!'''	)
															return False




							def 						__snake_case					(   self     :   List[str]	):
											return -0.18 + (1.17 * ((self.nir - self.red) / (self.nir + self.red)))




							def 						__snake_case					(   self     :   Optional[int]	):
											return ((self.nir - self.redEdge) / (self.nir + self.redEdge)) / (
											    (self.nir - self.red) / (self.nir + self.red)
											)




							def 						__snake_case					(   self     :   str	):
											return self.nir * (self.red / (self.green**2))




							def 						__snake_case					(   self     :   List[str]	):
											return (2 * self.green - self.red - self.blue) / (
											    2 * self.green + self.red + self.blue
											)




							def 						__snake_case					(   self     :   List[str]	):
											return (self.nir - self.red) / (self.nir + self.red)




							def 						__snake_case					(   self     :   Optional[Any]	):
											return (self.nir - self.blue) / (self.nir + self.blue)




							def 						__snake_case					(   self     :   Optional[Any]	):
											return (self.redEdge - self.red) / (self.redEdge + self.red)




							def 						__snake_case					(   self     :   Tuple	):
											return (self.nir - self.green) / (self.nir + self.green)




							def 						__snake_case					(   self     :   List[Any]	):
											return (self.nir - (self.green + self.blue)) / (
											    self.nir + (self.green + self.blue)
											)




							def 						__snake_case					(   self     :   Optional[int]	):
											return (self.nir - (self.green + self.red)) / (
											    self.nir + (self.green + self.red)
											)




							def 						__snake_case					(   self     :   Optional[Any]	):
											return (self.nir - (self.blue + self.red)) / (self.nir + (self.blue + self.red))




							def 						__snake_case					(   self     :   Optional[int]	):
											return (self.nir - (self.green + self.red + self.blue)) / (
											    self.nir + (self.green + self.red + self.blue)
											)




							def 						__snake_case					(   self     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   List[Any]=0.08 ,							SCREAMING_SNAKE_CASE_     :   List[str]=1.22 ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]=0.03	):
											return a * (
											    (self.nir - a * self.red - b)
											    / (a * self.nir + self.red - a * b + x * (1 + a**2))
											)




							def 						__snake_case					(   self     :   Tuple	):
											return (0.1 * self.nir - self.blue) / (0.1 * self.nir + self.blue)




							def 						__snake_case					(   self     :   Dict	):
											return (self.nir / self.green) - 1




							def 						__snake_case					(   self     :   str	):
											return (self.nir / self.redEdge) - 1




							def 						__snake_case					(   self     :   Tuple	):
											return (self.red - self.blue) / self.red




							def 						__snake_case					(   self     :   Any	):
											lowerCAmelCase__      			=						self.ndvi()
											return ((ndvi + 0.5) / (abs(ndvi + 0.5	))) * (abs(ndvi + 0.5	) ** (1 / 2))




							def 						__snake_case					(   self     :   Dict	):
											return self.nir - self.green




							def 						__snake_case					(   self     :   List[Any]	):
											return 2.5 * (
											    (self.nir - self.red) / (self.nir + 6 * self.red - 7.5 * self.blue + 1)
											)




							def 						__snake_case					(   self     :   Tuple	):
											lowerCAmelCase__      			=						(2 * (self.nir**2 - self.red**2) + 1.5 * self.nir + 0.5 * self.red) / (
											    self.nir + self.red + 0.5
											)
											return n * (1 - 0.25 * n) - (self.red - 0.125) / (1 - self.red)




							def 						__snake_case					(   self     :   Optional[Any] ,							SCREAMING_SNAKE_CASE_     :   Dict=0.16	):
											return (self.nir - self.green) / (self.nir + self.green + y)




							def 						__snake_case					(   self     :   Optional[int] ,							SCREAMING_SNAKE_CASE_     :   Any=0.5	):
											return ((self.nir - self.green) / (self.nir + self.green + n)) * (1 + n)




							def 						__snake_case					(   self     :   Any	):
											return np.arctan(
											    ((2 * self.red - self.green - self.blue) / 30.5) * (self.green - self.blue)	)




							def 						__snake_case					(   self     :   List[str] ,							SCREAMING_SNAKE_CASE_     :   List[str]=None ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]=None	):
											return (self.nir - b) / (a * self.red)




							def 						__snake_case					(   self     :   Union[str, Any]	):
											return (self.nir / ((self.nir + self.red) / 2)) * (self.ndvi() + 1)




							def 						__snake_case					(   self     :   List[str]	):
											return (self.red + self.green + self.blue) / 30.5




							def 						__snake_case					(   self     :   Optional[int]	):
											return self.nir / self.red




							def 						__snake_case					(   self     :   Dict	):
											return (self.rvi() - 1) / (self.rvi() + 1)




							def 						__snake_case					(   self     :   Union[str, Any]	):
											return (
											    (2 * self.nir + 1)
											    - ((2 * self.nir + 1) ** 2 - 8 * (self.nir - self.red)) ** (1 / 2)
											) / 2




							def 						__snake_case					(   self     :   List[Any]	):
											return self.green / (self.nir + self.red + self.green)




							def 						__snake_case					(   self     :   List[str]	):
											return self.nir / (self.nir + self.red + self.green)




							def 						__snake_case					(   self     :   Any	):
											return self.red / (self.nir + self.red + self.green)




							def 						__snake_case					(   self     :   Union[str, Any]	):
											return (self.green - self.red) / (self.green + self.red)




							def 						__snake_case					(   self     :   Dict	):
											return (self.red - self.green) / (self.red + self.green)




							def 						__snake_case					(   self     :   Optional[int]	):
											lowerCAmelCase__      			=						np.max([np.max(self.red	), np.max(self.green	), np.max(self.blue	)]	)
											lowerCAmelCase__      			=						np.min([np.min(self.red	), np.min(self.green	), np.min(self.blue	)]	)
											return (max_value - min_value) / max_value




							def 						__snake_case					(   self     :   str	):
											return (2 * self.red - self.green - self.blue) / (self.green - self.blue)




							def 						__snake_case					(   self     :   Optional[Any]	):
											return self.nir / self.red




							def 						__snake_case					(   self     :   Union[str, Any]	):
											return (self.ndvi() + 0.5) ** (1 / 2)




							def 						__snake_case					(   self     :   List[Any]	):
											return (self.nir - self.redEdge) / (self.nir + self.redEdge)





