
from __future__ import annotations

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

lowercase_ 				=			TypeVar("""T""")





class     __UpperCamelCase (							Generic[T]       ):






     """simple docstring"""







     def __init__(				self							:							List[Any]     ,						_A							:							list[T]     ,						_A							:							Callable[[T, T], T] ):







       """simple docstring"""




       __SCREAMING_SNAKE_CASE      :	Any | T					=		None

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



     def  UpperCAmelCase__							(				self							:							List[Any] ):







       """simple docstring"""




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



     def  UpperCAmelCase__							(				self							:							str     ,						_A							:							int     ,						_A							:							T ):







       """simple docstring"""




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




     def  UpperCAmelCase__							(				self							:							int     ,						_A							:							int     ,						_A							:							int ):  # noqa: E741







       """simple docstring"""




       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	Tuple					=		l + self.N, r + self.N

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


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

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

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

   lowercase_ 				=			SegmentTree(test_array, min)
   lowercase_ 				=			SegmentTree(test_array, max)
   lowercase_ 				=			SegmentTree(test_array, lambda a, b: a + b)


   def 							a__					(							):





     """simple docstring"""
     for i in range(len(snake_case							)							):
       for j in range(snake_case       ,			len(snake_case							)							):
         __SCREAMING_SNAKE_CASE      :	Any					=		reduce(snake_case       ,			test_array[i : j + 1]							)
         __SCREAMING_SNAKE_CASE      :	Tuple					=		reduce(snake_case       ,			test_array[i : j + 1]							)
         __SCREAMING_SNAKE_CASE      :	str					=		reduce(lambda snake_case       ,			snake_case							: a + b       ,			test_array[i : j + 1]							)
         assert min_range == min_segment_tree.query(snake_case       ,			snake_case							)
         assert max_range == max_segment_tree.query(snake_case       ,			snake_case							)
         assert sum_range == sum_segment_tree.query(snake_case       ,			snake_case							)

   test_all_segments()

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






"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase__			=		logging.get_logger(__name__)

lowercase__			=		{"""openai-gpt""": """https://huggingface.co/openai-gpt/resolve/main/config.json"""}






class lowerCAmelCase__      (	lowercase		):






			'''simple docstring'''



			lowerCamelCase__ =     """openai-gpt"""
			lowerCamelCase__ =     {
			    """max_position_embeddings""": """n_positions""",
			    """hidden_size""": """n_embd""",
			    """num_attention_heads""": """n_head""",
			    """num_hidden_layers""": """n_layer""",
			}
			def __init__(    self    , lowercase=40478    , lowercase=512    , lowercase=768    , lowercase=12    , lowercase=12    , lowercase="gelu"    , lowercase=0.1    , lowercase=0.1    , lowercase=0.1    , lowercase=1E-5    , lowercase=0.02    , lowercase="cls_index"    , lowercase=True    , lowercase=None    , lowercase=True    , lowercase=0.1    , **lowercase    , ):
							_lowerCamelCase	:     Tuple       =       vocab_size
							_lowerCamelCase	:     List[str]       =       n_positions
							_lowerCamelCase	:     Tuple       =       n_embd
							_lowerCamelCase	:     Optional[int]       =       n_layer
							_lowerCamelCase	:     List[Any]       =       n_head
							_lowerCamelCase	:     Dict       =       afn
							_lowerCamelCase	:     Union[str, Any]       =       resid_pdrop
							_lowerCamelCase	:     Dict       =       embd_pdrop
							_lowerCamelCase	:     List[Any]       =       attn_pdrop
							_lowerCamelCase	:     Any       =       layer_norm_epsilon
							_lowerCamelCase	:     List[Any]       =       initializer_range
							_lowerCamelCase	:     List[Any]       =       summary_type
							_lowerCamelCase	:     List[str]       =       summary_use_proj
							_lowerCamelCase	:     Tuple       =       summary_activation
							_lowerCamelCase	:     int       =       summary_first_dropout
							_lowerCamelCase	:     str       =       summary_proj_to_labels
							super().__init__(**lowercase    )