
from collections.abc import Sequence
from queue import Queue





class 				A__						:
      def __init__( self       ,    __magic_name__       ,    __magic_name__       ,    __magic_name__       ,    __magic_name__=None       ,    __magic_name__=None ):
       lowerCamelCase						:      Union[str, Any]							     = start
       lowerCamelCase						:      List[str]							     = end
       lowerCamelCase						:      List[str]							     = val
       lowerCamelCase						:      Optional[Any]							     = (start + end) // 2
       lowerCamelCase						:      List[str]							     = left
       lowerCamelCase						:      Optional[int]							     = right






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





class 				A__						:
      def __init__( self       ,    __magic_name__       ,    __magic_name__ ):
       lowerCamelCase						:      Optional[int]							     = collection
       lowerCamelCase						:      Optional[int]							     = function
       if self.collection:
        lowerCamelCase						:      Dict							     = self._build_tree(0       ,    len(__magic_name__ ) - 1 )
      def 		UpperCamelCase__				( self       ,    __magic_name__       ,    __magic_name__ ):
       self._update_tree(self.root       ,    __magic_name__       ,    __magic_name__ )
      def 		UpperCamelCase__				( self       ,    __magic_name__       ,    __magic_name__ ):
       return self._query_range(self.root       ,    __magic_name__       ,    __magic_name__ )
      def 		UpperCamelCase__				( self       ,    __magic_name__       ,    __magic_name__ ):







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







       if node.start == i and node.end == i:
        lowerCamelCase						:      str							     = val
        return
       if i <= node.mid:
        self._update_tree(node.left       ,    __magic_name__       ,    __magic_name__ )
       else:
        self._update_tree(node.right       ,    __magic_name__       ,    __magic_name__ )
       lowerCamelCase						:      List[str]							     = self.fn(node.left.val       ,    node.right.val )
      def 		UpperCamelCase__				( self       ,    __magic_name__       ,    __magic_name__       ,    __magic_name__ ):







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






      def 		UpperCamelCase__				( self ):







       if self.root is not None:
        lowerCamelCase						:      Union[str, Any]							     = Queue()
        queue.put(self.root )
        while not queue.empty():
         lowerCamelCase						:      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)
            _lowerCamelCase     =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()








UpperCAmelCase   :    Any     =		[0, 2, 4, 6, 8]
UpperCAmelCase   :    Optional[Any]     =		[1, 3, 5, 7, 9]






def 	__lowerCamelCase						(							lowerCamelCase__		:						int  ,							lowerCamelCase__		:						int  ,							lowerCamelCase__		:						list[int]  ,							lowerCamelCase__		:						int      ):





			'''simple docstring'''




			if remaining_length == 0:
						if digits[0] == 0 or digits[-1] == 0:
									return 0

						for i in range(length // 2 - 1  ,							-1  ,							-1      ):
									remainder += digits[i] + digits[length - i - 1]

									if remainder % 2 == 0:
												return 0

									remainder //= 10

						return 1

			if remaining_length == 1:
						if remainder % 2 == 0:
									return 0

						lowerCamelCase    		=  0
						for digit in range(10      ):
									lowerCamelCase    		=  digit
									result += reversible_numbers(
									    0  ,							(remainder + 2 * digit) // 10  ,							lowerCamelCase__  ,							lowerCamelCase__      )
						return result

			lowerCamelCase    		=  0
			for digita in range(10      ):
						lowerCamelCase    		=  digita

						if (remainder + digita) % 2 == 0:
									lowerCamelCase    		=  ODD_DIGITS
						else:
									lowerCamelCase    		=  EVEN_DIGITS

						for digita in other_parity_digits:
									lowerCamelCase    		=  digita
									result += reversible_numbers(
									    remaining_length - 2  ,							(remainder + digita + digita) // 10  ,							lowerCamelCase__  ,							lowerCamelCase__  ,							)
			return result






def 	__lowerCamelCase						(							lowerCamelCase__		:						int = 9      ):





			'''simple docstring'''




			lowerCamelCase    		=  0
			for length in range(1  ,							max_power + 1      ):
						result += reversible_numbers(lowerCamelCase__  ,							0  ,							[0] * length  ,							lowerCamelCase__      )
			return result


if __name__ == "__main__":
		print(f"""{solution() = }""")

