






from __future__ import annotations

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

SCREAMING_SNAKE_CASE__   :      Optional[Any]				=		TypeVar("""T""")
class     lowerCamelCase_					(   Generic[T]			):







				def __init__(    self							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:Any | T   =   None

								__magic_name__		:int   =   len(__lowerCAmelCase  )
								__magic_name__		:list[T]   =   [any_type for _ in range(self.N  )] + arr
								__magic_name__		:List[str]   =   fnc
								self.build()







				def       A						(    self  ):
								"""simple docstring"""
								for p in range(self.N - 1							,       0							,       -1  ):
												__magic_name__		:Dict   =   self.fn(self.st[p * 2]							,       self.st[p * 2 + 1]  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								p += self.N
								__magic_name__		:Optional[Any]   =   v
								while p > 1:
												__magic_name__		:Optional[Any]   =   p // 2
												__magic_name__		:Optional[Any]   =   self.fn(self.st[p * 2]							,       self.st[p * 2 + 1]  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase  ):  # noqa: E741
								"""simple docstring"""
								__magic_name__  ,					__magic_name__		:int   =   l + self.N, r + self.N

								__magic_name__		:T | None   =   None
								while l <= r:
												if l % 2 == 1:
																__magic_name__		:int   =   self.st[l] if res is None else self.fn(__lowerCAmelCase							,       self.st[l]  )
												if r % 2 == 0:
																__magic_name__		:List[Any]   =   self.st[r] if res is None else self.fn(__lowerCAmelCase							,       self.st[r]  )
												__magic_name__  ,					__magic_name__		:List[str]   =   (l + 1) // 2, (r - 1) // 2
								return res


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

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

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

					SCREAMING_SNAKE_CASE__   :      Union[str, Any]				=		SegmentTree(test_array, min)
					SCREAMING_SNAKE_CASE__   :      Any				=		SegmentTree(test_array, max)
					SCREAMING_SNAKE_CASE__   :      Any				=		SegmentTree(test_array, lambda a, b: a + b)

					def   __lowercase       (			):







									"""simple docstring"""






									for i in range(len(snake_case			)			):
													for j in range(snake_case,	len(snake_case			)			):
																	__magic_name__		:int   =   reduce(snake_case,	test_array[i : j + 1]			)
																	__magic_name__		:List[Any]   =   reduce(snake_case,	test_array[i : j + 1]			)
																	__magic_name__		:Dict   =   reduce(lambda snake_case,	snake_case			: a + b,	test_array[i : j + 1]			)
																	assert min_range == min_segment_tree.query(snake_case,	snake_case			)
																	assert max_range == max_segment_tree.query(snake_case,	snake_case			)
																	assert sum_range == sum_segment_tree.query(snake_case,	snake_case			)

					test_all_segments()

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














def   __lowercase       (			snake_case			):







				"""simple docstring"""






				return "".join([hex(snake_case			)[2:].zfill(2			).upper() for byte in list(snake_case			)]			)

def   __lowercase       (			snake_case			):







				"""simple docstring"""






				if (len(snake_case			) % 2) != 0:
								raise ValueError(
								    '''Base16 encoded data is invalid:
Data does not have an even number of hex digits.'''			)
				# Check the character set - the standard base16 alphabet
				# is uppercase according to RFC3548 section 6
				if not set(snake_case			) <= set('''0123456789ABCDEF'''			):
								raise ValueError(
								    '''Base16 encoded data is invalid:
Data is not uppercase hex or it contains invalid characters.'''			)
				# For every two hexadecimal digits (= a byte), turn it into an integer.
				# Then, string the result together into bytes, and return it.
				return bytes(int(data[i] + data[i + 1],	1_6			) for i in range(0,	len(snake_case			),	2			)			)


if __name__ == "__main__":
					import doctest

					doctest.testmod()






