





from collections.abc import Sequence
from queue import Queue





class  A__    :




   """simple docstring"""



   def __init__(					self					,  lowercase					,  lowercase					,  lowercase					,  lowercase=None					,  lowercase=None)			->						Dict:







          '''simple docstring'''

          a__						:	Tuple =				start
          a__						:	Any =				end
          a__						:	Optional[Any] =				val
          a__						:	Optional[Any] =				(start + end) // 2
          a__						:	Optional[Any] =				left
          a__						:	Any =				right

   def __repr__(					self)			->						int:







          '''simple docstring'''

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





class  A__    :




   """simple docstring"""



   def __init__(					self					,  lowercase					,  lowercase)			->						Optional[Any]:







          '''simple docstring'''

          a__						:	Tuple =				collection
          a__						:	Tuple =				function
          if self.collection:
                 a__						:	str =				self._build_tree(0					,  len(lowercase) - 1)

   def 							__lowercase		(					self					,  lowercase					,  lowercase)			->						str:







          '''simple docstring'''

          self._update_tree(self.root					,  lowercase					,  lowercase)

   def 							__lowercase		(					self					,  lowercase					,  lowercase)			->						List[str]:







          '''simple docstring'''

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

   def 							__lowercase		(					self					,  lowercase					,  lowercase)			->						Any:







          '''simple docstring'''

          if start == end:
                 return SegmentTreeNode(lowercase					,  lowercase					,  self.collection[start])
          a__						:	Union[str, Any] =				(start + end) // 2
          a__						:	Any =				self._build_tree(lowercase					,  lowercase)
          a__						:	str =				self._build_tree(mid + 1					,  lowercase)
          return SegmentTreeNode(lowercase					,  lowercase					,  self.fn(left.val					,  right.val)					,  lowercase					,  lowercase)

   def 							__lowercase		(					self					,  lowercase					,  lowercase					,  lowercase)			->						Union[str, Any]:







          '''simple docstring'''

          if node.start == i and node.end == i:
                 a__						:	Tuple =				val
                 return
          if i <= node.mid:
                 self._update_tree(node.left					,  lowercase					,  lowercase)
          else:
                 self._update_tree(node.right					,  lowercase					,  lowercase)
          a__						:	Union[str, Any] =				self.fn(node.left.val					,  node.right.val)

   def 							__lowercase		(					self					,  lowercase					,  lowercase					,  lowercase)			->						Tuple:







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

   def 							__lowercase		(					self)			->						str:







          '''simple docstring'''

          if self.root is not None:
                 a__						:	List[str] =				Queue()
                 queue.put(self.root)
                 while not queue.empty():
                        a__						:	int =				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      :       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()









def A_	(		A__		,      A__				)  ->		str:
       if a < 0 or b < 0:
              raise ValueError('the value of both inputs must be positive'				)

       a__						:	List[str] =				str(bin(A__				)				)[2:]  # remove the leading "0b"
       a__						:	Optional[int] =				str(bin(A__				)				)[2:]  # remove the leading "0b"

       a__						:	List[str] =				max(len(A__				)		,      len(A__				)				)

       return "0b" + "".join(
           str(int(char_a == '1' and char_b == '1'				)				)
           for char_a, char_b in zip(a_binary.zfill(A__				)		,      b_binary.zfill(A__				)				)				)


if __name__ == "__main__":
    import doctest

    doctest.testmod()


