
'''simple docstring'''







from collections.abc import Sequence
from queue import Queue






class 			lowerCAmelCase__       :






					def __init__(       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE=None    ,							__SCREAMING_SNAKE_CASE=None		):


											"""simple docstring"""





											lowercase_     :					Optional[int]													=	start
											lowercase_     :					List[Any]													=	end
											lowercase_     :					Tuple													=	val
											lowercase_     :					Union[str, Any]													=	(start + end) // 2
											lowercase_     :					Optional[Any]													=	left
											lowercase_     :					Tuple													=	right






					def __repr__(       self		):


											"""simple docstring"""





											return F'''SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})'''







class 			lowerCAmelCase__       :






					def __init__(       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





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






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											self._update_tree(self.root    ,							lowerCAmelCase__    ,							lowerCAmelCase__		)






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											return self._query_range(self.root    ,							lowerCAmelCase__    ,							lowerCAmelCase__		)






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if start == end:
																	return SegmentTreeNode(lowerCAmelCase__    ,							lowerCAmelCase__    ,							self.collection[start]		)
											lowercase_     :					Optional[Any]													=	(start + end) // 2
											lowercase_     :					Tuple													=	self._build_tree(lowerCAmelCase__    ,							lowerCAmelCase__		)
											lowercase_     :					Optional[Any]													=	self._build_tree(mid + 1    ,							lowerCAmelCase__		)
											return SegmentTreeNode(lowerCAmelCase__    ,							lowerCAmelCase__    ,							self.fn(left.val    ,							right.val		)    ,							lowerCAmelCase__    ,							lowerCAmelCase__		)






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if node.start == i and node.end == i:
																	lowercase_     :					int													=	val
																	return
											if i <= node.mid:
																	self._update_tree(node.left    ,							lowerCAmelCase__    ,							lowerCAmelCase__		)
											else:
																	self._update_tree(node.right    ,							lowerCAmelCase__    ,							lowerCAmelCase__		)
											lowercase_     :					Dict													=	self.fn(node.left.val    ,							node.right.val		)






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											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    ,							lowerCAmelCase__    ,							lowerCAmelCase__		)
																	else:
																							# range in left child tree and right child tree
																							return self.fn(
																							    self._query_range(node.left    ,							lowerCAmelCase__    ,							node.mid		)    ,							self._query_range(node.right    ,							node.mid + 1    ,							lowerCAmelCase__		)    ,							)
											else:
																	# range in right child tree
																	return self._query_range(node.right    ,							lowerCAmelCase__    ,							lowerCAmelCase__		)






					def      _snake_case   (       self		):


											"""simple docstring"""





											if self.root is not None:
																	lowercase_     :					Dict													=	Queue()
																	queue.put(self.root		)
																	while not queue.empty():
																							lowercase_     :					Any													=	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("*" * 5_0)
												_lowercase			:  Union[str, Any]   							=	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()





'''simple docstring'''







from PIL import Image
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			Image				,				__SCREAMING_SNAKE_CASE :			int							):



						"""simple docstring"""





						lowercase_     :					Optional[int]													=	(259 * (level + 255)) / (255 * (259 - level))

						def contrast(__SCREAMING_SNAKE_CASE :			int							) -> int:
												return int(128 + factor * (c - 128)							)

						return img.point(__SCREAMING_SNAKE_CASE							)


if __name__ == "__main__":
							# Load image
							with Image.open("image_data/lena.jpg") as img:
														# Change contrast to 170
														_lowercase			:  Union[str, Any]   							=	change_contrast(img, 1_7_0)
														cont_img.save("image_data/lena_high_contrast.png", format="png")



