




from collections.abc import Sequence
from queue import Queue







class 						A:



 '''simple docstring'''


 def __init__(       self      :						Tuple		,							A_      :						Any		,							A_      :						Tuple		,							A_      :						List[str]		,							A_      :						Dict=None		,							A_      :						Optional[int]=None						)     ->			Optional[int]:

       """simple docstring"""






       lowerCamelCase_	  =					start
       lowerCamelCase_	  =					end
       lowerCamelCase_	  =					val
       lowerCamelCase_	  =					(start + end) // 2
       lowerCamelCase_	  =					left
       lowerCamelCase_	  =					right





 def __repr__(       self      :						List[Any]						)     ->			Any:

       """simple docstring"""






       return f"""SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})"""







class 						A:



 '''simple docstring'''


 def __init__(       self      :						List[str]		,							A_      :						str		,							A_      :						List[str]						)     ->			Optional[int]:

       """simple docstring"""






       lowerCamelCase_	  =					collection
       lowerCamelCase_	  =					function
       if self.collection:
             lowerCamelCase_	  =					self._build_tree(0		,							len(UpperCAmelCase_						) - 1						)

 def        a__				(       self      :						Tuple		,							A_      :						int		,							A_      :						str						)     ->			Dict:

       """simple docstring"""






       self._update_tree(self.root		,							UpperCAmelCase_		,							UpperCAmelCase_						)

 def        a__				(       self      :						int		,							A_      :						Optional[int]		,							A_      :						Dict						)     ->			str:

       """simple docstring"""






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

 def        a__				(       self      :						Union[str, Any]		,							A_      :						Any		,							A_      :						Optional[Any]						)     ->			List[str]:

       """simple docstring"""






       if start == end:
             return SegmentTreeNode(UpperCAmelCase_		,							UpperCAmelCase_		,							self.collection[start]						)
       lowerCamelCase_	  =					(start + end) // 2
       lowerCamelCase_	  =					self._build_tree(UpperCAmelCase_		,							UpperCAmelCase_						)
       lowerCamelCase_	  =					self._build_tree(mid + 1		,							UpperCAmelCase_						)
       return SegmentTreeNode(UpperCAmelCase_		,							UpperCAmelCase_		,							self.fn(left.val		,							right.val						)		,							UpperCAmelCase_		,							UpperCAmelCase_						)

 def        a__				(       self      :						Optional[int]		,							A_      :						Optional[int]		,							A_      :						str		,							A_      :						List[Any]						)     ->			Tuple:

       """simple docstring"""






       if node.start == i and node.end == i:
             lowerCamelCase_	  =					val
             return
       if i <= node.mid:
             self._update_tree(node.left		,							UpperCAmelCase_		,							UpperCAmelCase_						)
       else:
             self._update_tree(node.right		,							UpperCAmelCase_		,							UpperCAmelCase_						)
       lowerCamelCase_	  =					self.fn(node.left.val		,							node.right.val						)

 def        a__				(       self      :						Tuple		,							A_      :						Optional[Any]		,							A_      :						Union[str, Any]		,							A_      :						Union[str, Any]						)     ->			List[str]:

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





 def        a__				(       self      :						Dict						)     ->			Optional[Any]:

       """simple docstring"""






       if self.root is not None:
             lowerCamelCase_	  =					Queue()
             queue.put(self.root						)
             while not queue.empty():
                   lowerCamelCase_	  =					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("*" * 50)
  lowerCamelCase       :	Optional[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()









def     _SCREAMING_SNAKE_CASE    (							):


      '''simple docstring'''



      lowerCamelCase_	  =					0
      for i in range(1			,							10_01  ):
            total += i**i
      return str(lowercase  )[-10:]


if __name__ == "__main__":
 print(solution())



