





'''simple docstring'''






from __future__ import annotations

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

A   : Dict             =			TypeVar('T')







class 			lowerCamelCase					(						Generic[T]  ):


     def __init__(					self	:  Dict       ,     __snake_case	:  int       ,     __snake_case	:  int       ):





           '''simple docstring'''





           _snake_case:   Any | T  					=		None

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


     def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





           '''simple docstring'''





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


     def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ,     __snake_case	:  Tuple       ,     __snake_case	:  Dict       ):





           '''simple docstring'''





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




     def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Tuple       ):  # noqa: E741





           '''simple docstring'''





           _snake_case:   List[Any]  					=		l + self.N, r + self.N

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


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

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

  A   : List[Any]             =			{
      0: 7,
      1: 2,
      2: 6,
      3: -14,
      4: 5,
      5: 4,
      6: 7,
      7: -10,
      8: 9,
      9: 10,
      10: 12,
      11: 1,
  }

  A   : Dict             =			SegmentTree(test_array, min)
  A   : str             =			SegmentTree(test_array, max)
  A   : str             =			SegmentTree(test_array, lambda a, b: a + b)





  def       lowercase_      (		)   ->None:
        for i in range(len(lowercase_						)						):
              for j in range(lowercase_				,  len(lowercase_						)						):
                    _snake_case:   List[str]  					=		reduce(lowercase_				,  test_array[i : j + 1]						)
                    _snake_case:   Any  					=		reduce(lowercase_				,  test_array[i : j + 1]						)
                    _snake_case:   Tuple  					=		reduce(lambda lowercase__				,  lowercase__						: a + b				,  test_array[i : j + 1]						)
                    assert min_range == min_segment_tree.query(lowercase_				,  lowercase_						)
                    assert max_range == max_segment_tree.query(lowercase_				,  lowercase_						)
                    assert sum_range == sum_segment_tree.query(lowercase_				,  lowercase_						)

  test_all_segments()

  for index, value in test_updates.items():
    A   : Optional[int]             =			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 __future__ import annotations

import sys
from collections import deque
from typing import Generic, TypeVar

A   : str             =			TypeVar('T')







class 			lowerCamelCase					(						Generic[T]  ):
					_SCREAMING_SNAKE_CASE							   =    42  # Cache store of keys
					_SCREAMING_SNAKE_CASE							   =    42  # References of the keys in cache
					_SCREAMING_SNAKE_CASE							   =    10  # Maximum capacity of cache


					def __init__(					self	:  List[Any]       ,     __snake_case	:  int       ):





											'''simple docstring'''





											_snake_case:   Dict  					=		deque()
											_snake_case:   Union[str, Any]  					=		set()
											if not n:
																	_snake_case:   Optional[int]  					=		sys.maxsize
											elif n < 0:
																	raise ValueError('n should be an integer greater than 0.'       )
											else:
																	_snake_case:   Tuple  					=		n


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ,     __snake_case	:  T       ):





											'''simple docstring'''





											if x not in self.key_reference:
																	if len(self.dq_store       ) == LRUCache._MAX_CAPACITY:
																							_snake_case:   int  					=		self.dq_store.pop()
																							self.key_reference.remove(__snake_case       )
											else:
																	self.dq_store.remove(__snake_case       )

											self.dq_store.appendleft(__snake_case       )
											self.key_reference.add(__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  int       ):





											'''simple docstring'''





											for k in self.dq_store:
																	print(__snake_case       )




					def __repr__(					self	:  List[Any]       ):





											'''simple docstring'''





											return f'''LRUCache({self._MAX_CAPACITY}) => {list(self.dq_store       )}'''


if __name__ == "__main__":
		import doctest

		doctest.testmod()

		A   : LRUCache[str | int]             =			LRUCache(4)
		lru_cache.refer('A')
		lru_cache.refer(2)
		lru_cache.refer(3)
		lru_cache.refer('A')
		lru_cache.refer(4)
		lru_cache.refer(5)
		lru_cache.display()

		print(lru_cache)
		assert str(lru_cache) == "LRUCache(4) => [5, 4, 'A', 3]"





