from __future__ import annotations

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

lowerCAmelCase			:							Optional[int]     =TypeVar("T")




class 	__snake_case	( Generic[T]		):





      '''simple docstring'''






      def __init__(					self     :				Tuple    ,  _UpperCamelCase     :				list[T]    ,  _UpperCamelCase     :				Callable[[T, T], T])				->None:


          """simple docstring"""


          _lowerCamelCase     :		Any | T 						=						None

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



      def 	_SCREAMING_SNAKE_CASE    (					self     :				Optional[int])				->None:


          """simple docstring"""


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



      def 	_SCREAMING_SNAKE_CASE    (					self     :				List[Any]    ,  _UpperCamelCase     :				int    ,  _UpperCamelCase     :				T)				->None:


          """simple docstring"""


          p += self.N
          _lowerCamelCase     :		List[Any] 						=						v
          while p > 1:
              _lowerCamelCase     :		Union[str, Any] 						=						p // 2
              _lowerCamelCase     :		List[Any] 						=						self.fn(self.st[p * 2]    ,  self.st[p * 2 + 1])




      def 	_SCREAMING_SNAKE_CASE    (					self     :				Optional[int]    ,  _UpperCamelCase     :				int    ,  _UpperCamelCase     :				int)				->T | None:  # noqa: E741


          """simple docstring"""


          _lowerCamelCase     :		List[str] 						=						l + self.N, r + self.N

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


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

    lowerCAmelCase			:							Optional[int]     =[1, 10, -2, 9, -3, 8, 4, -7, 5, 6, 11, -12]

    lowerCAmelCase			:							str     ={
        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			:							Union[str, Any]     =SegmentTree(test_array, min)
    lowerCAmelCase			:							Any     =SegmentTree(test_array, max)
    lowerCAmelCase			:							Any     =SegmentTree(test_array, lambda a, b: a + b)







    def 						A__  (					):







        '''simple docstring'''
        for i in range(len(__A	)	):
            for j in range(__A   , len(__A	)	):
                _lowerCamelCase     :		Optional[int] 						=						reduce(__A   , test_array[i : j + 1]	)
                _lowerCamelCase     :		Union[str, Any] 						=						reduce(__A   , test_array[i : j + 1]	)
                _lowerCamelCase     :		Union[str, Any] 						=						reduce(lambda __A   , __A	: a + b   , test_array[i : j + 1]	)
                assert min_range == min_segment_tree.query(__A   , __A	)
                assert max_range == max_segment_tree.query(__A   , __A	)
                assert sum_range == sum_segment_tree.query(__A   , __A	)

    test_all_segments()

    for index, value in test_updates.items():
        lowerCAmelCase			:							Union[str, Any]     =value
        min_segment_tree.update(index, value)
        max_segment_tree.update(index, value)
        sum_segment_tree.update(index, value)
        test_all_segments()





from typing import Optional

from .. import Features, NamedSplit
from ..packaged_modules.text.text import Text
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader




class 	__snake_case	( __lowerCAmelCase		):





      '''simple docstring'''






      def __init__(					self     :				Dict    ,  _UpperCamelCase     :				NestedDataStructureLike[PathLike]    ,  _UpperCamelCase     :				Optional[NamedSplit] = None    ,  _UpperCamelCase     :				Optional[Features] = None    ,  _UpperCamelCase     :				str = None    ,  _UpperCamelCase     :				bool = False    ,  _UpperCamelCase     :				bool = False    ,  _UpperCamelCase     :				Optional[int] = None    ,  **_UpperCamelCase     :				Tuple    ,  )				->Union[str, Any]:


          """simple docstring"""


          super().__init__(
              _UpperCamelCase    ,  split=_UpperCamelCase    ,  features=_UpperCamelCase    ,  cache_dir=_UpperCamelCase    ,  keep_in_memory=_UpperCamelCase    ,  streaming=_UpperCamelCase    ,  num_proc=_UpperCamelCase    ,  **_UpperCamelCase    ,  )
          _lowerCamelCase     :		List[Any] 						=						path_or_paths if isinstance(_UpperCamelCase    ,  _UpperCamelCase) else {self.split: path_or_paths}
          _lowerCamelCase     :		Any 						=						Text(
              cache_dir=_UpperCamelCase    ,  data_files=_UpperCamelCase    ,  features=_UpperCamelCase    ,  **_UpperCamelCase    ,  )




      def 	_SCREAMING_SNAKE_CASE    (					self     :				Optional[Any])				->Optional[Any]:


          """simple docstring"""


          if self.streaming:
              _lowerCamelCase     :		Tuple 						=						self.builder.as_streaming_dataset(split=self.split)
          # Build regular (map-style) dataset
          else:
              _lowerCamelCase     :		List[Any] 						=						None
              _lowerCamelCase     :		Any 						=						None
              _lowerCamelCase     :		List[str] 						=						None
              _lowerCamelCase     :		Dict 						=						None

              self.builder.download_and_prepare(
                  download_config=_UpperCamelCase    ,  download_mode=_UpperCamelCase    ,  verification_mode=_UpperCamelCase    ,  base_path=_UpperCamelCase    ,  num_proc=self.num_proc    ,  )
              _lowerCamelCase     :		Optional[int] 						=						self.builder.as_dataset(
                  split=self.split    ,  verification_mode=_UpperCamelCase    ,  in_memory=self.keep_in_memory)
          return dataset




