





"""simple docstring"""







from __future__ import annotations

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

a__      :	Optional[Any]       				=      TypeVar("""T""")




class __magic_name__   (       Generic[T]		):
       def __init__(     self   ,  __magic_name__   ,  __magic_name__	):





         """simple docstring"""


         _lowerCAmelCase	      =					None

         _lowerCAmelCase	      =					len(__lowerCAmelCase	)
         _lowerCAmelCase	      =					[any_type for _ in range(self.N	)] + arr
         _lowerCAmelCase	      =					fnc
         self.build()
       def 		_lowerCamelCase   (     self	):





         """simple docstring"""


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





         """simple docstring"""


         p += self.N
         _lowerCAmelCase	      =					v
         while p > 1:
           _lowerCAmelCase	      =					p // 2
           _lowerCAmelCase	      =					self.fn(self.st[p * 2]   ,  self.st[p * 2 + 1]	)
       def 		_lowerCamelCase   (     self   ,  __magic_name__   ,  __magic_name__	):  # noqa: E741





         """simple docstring"""


         _lowerCAmelCase	      =					l + self.N, r + self.N

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


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

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

   a__      :	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,
   }

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







   def     A__			(       ):





     """simple docstring"""






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

   test_all_segments()

   for index, value in test_updates.items():
      a__      :	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()






