


from __future__ import annotations

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

lowerCAmelCase__      		= TypeVar('T')







class      lowerCAmelCase__       (				Generic[T]):




     '''simple docstring'''


     def __init__(						self ,						__lowerCamelCase ,						__lowerCamelCase)			->				None:
            _A      :       Any | T				    = None

            _A      :       int				    = len(__lowerCamelCase)
            _A      :       list[T]				    = [any_type for _ in range(self.N)] + arr
            _A      :       Any				    = fnc
            self.build()


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


     def  _lowerCamelCase (						self ,						__lowerCamelCase ,						__lowerCamelCase)			->				None:
            p += self.N
            _A      :       List[str]				    = v
            while p > 1:
                   _A      :       List[Any]				    = p // 2
                   _A      :       Optional[int]				    = self.fn(self.st[p * 2] ,						self.st[p * 2 + 1])


     def  _lowerCamelCase (						self ,						__lowerCamelCase ,						__lowerCamelCase)			->				T | None:  # noqa: E741
            _A    ,			_A      :       Optional[Any]				    = l + self.N, r + self.N

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


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

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

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

    lowerCAmelCase__      		= SegmentTree(test_array, min)
    lowerCAmelCase__      		= SegmentTree(test_array, max)
    lowerCAmelCase__      		= SegmentTree(test_array, lambda a, b: a + b)
    def 							_UpperCAmelCase				():
           for i in range(len(UpperCamelCase__						)						):
                  for j in range(UpperCamelCase__				,							len(UpperCamelCase__						)						):
                         _A      :       Any				    = reduce(UpperCamelCase__				,							test_array[i : j + 1]						)
                         _A      :       Optional[int]				    = reduce(UpperCamelCase__				,							test_array[i : j + 1]						)
                         _A      :       int				    = reduce(lambda UpperCamelCase__				,							UpperCamelCase__						: a + b				,							test_array[i : j + 1]						)
                         assert min_range == min_segment_tree.query(UpperCamelCase__				,							UpperCamelCase__						)
                         assert max_range == max_segment_tree.query(UpperCamelCase__				,							UpperCamelCase__						)
                         assert sum_range == sum_segment_tree.query(UpperCamelCase__				,							UpperCamelCase__						)

    test_all_segments()

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




from __future__ import annotations
def 							_UpperCAmelCase				(UpperCamelCase__     :  list[int]				,							UpperCamelCase__     :  list[int]				,							UpperCamelCase__     :  int						):
       _A      :       Dict				    = list(range(len(UpperCamelCase__						)						)						)
       _A      :       Any				    = [v / w for v, w in zip(UpperCamelCase__				,							UpperCamelCase__						)]
       index.sort(key=lambda UpperCamelCase__						: ratio[i]				,							reverse=UpperCamelCase__						)

       _A      :       float				    = 0
       _A      :       list[float]				    = [0] * len(UpperCamelCase__						)
       for i in index:
              if weight[i] <= capacity:
                     _A      :       Union[str, Any]				    = 1
                     max_value += value[i]
                     capacity -= weight[i]
              else:
                     _A      :       Optional[Any]				    = capacity / weight[i]
                     max_value += value[i] * capacity / weight[i]
                     break

       return max_value, fractions


if __name__ == "__main__":
    import doctest

    doctest.testmod()
