
class      A__							:






				def __init__(						self					:      Dict    ,     a					:      Any    ,     a					:      List[str]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Dict         =		name
							lowerCAmelCase__      :      Any         =		val






				def __str__(						self					:      Optional[Any]   ):






							'''simple docstring'''







							return f'''{self.__class__.__name__}({self.name}, {self.val})'''






				def __lt__(						self					:      Optional[Any]    ,     a					:      Optional[int]   ):






							'''simple docstring'''







							return self.val < other.val







class      A__							:






				def __init__(						self					:      Union[str, Any]    ,     a					:      List[str]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      List[str]         =		{}
							lowerCAmelCase__      :      Union[str, Any]         =		{}
							lowerCAmelCase__      :      Union[str, Any]         =		self.build_heap(a   )






				def __getitem__(						self					:      List[str]    ,     a					:      Optional[int]   ):






							'''simple docstring'''







							return self.get_value(a   )






				def 							_lowerCamelCase		(						self					:      Dict    ,     a					:      int   ):






							'''simple docstring'''







							return (idx - 1) // 2






				def 							_lowerCamelCase		(						self					:      List[str]    ,     a					:      Tuple   ):






							'''simple docstring'''







							return idx * 2 + 1






				def 							_lowerCamelCase		(						self					:      str    ,     a					:      Union[str, Any]   ):






							'''simple docstring'''







							return idx * 2 + 2






				def 							_lowerCamelCase		(						self					:      Optional[int]    ,     a					:      str   ):






							'''simple docstring'''







							return self.heap_dict[key]






				def 							_lowerCamelCase		(						self					:      str    ,     a					:      Optional[Any]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Optional[int]         =		len(a   ) - 1
							lowerCAmelCase__      :      str         =		self.get_parent_idx(a   )

							for idx, i in enumerate(a   ):
										lowerCAmelCase__      :      List[str]         =		idx
										lowerCAmelCase__      :      List[Any]         =		i.val

							for i in range(a    ,     -1    ,     -1   ):
										self.sift_down(a    ,     a   )
							return array






				def 							_lowerCamelCase		(						self					:      str    ,     a					:      str    ,     a					:      int   ):






							'''simple docstring'''







							while True:
										lowerCAmelCase__      :      Optional[int]         =		self.get_left_child_idx(a   )  # noqa: E741
										lowerCAmelCase__      :      Optional[Any]         =		self.get_right_child_idx(a   )

										lowerCAmelCase__      :      List[str]         =		idx
										if l < len(a   ) and array[l] < array[idx]:
													lowerCAmelCase__      :      Any         =		l
										if r < len(a   ) and array[r] < array[smallest]:
													lowerCAmelCase__      :      Any         =		r

										if smallest != idx:
													lowerCAmelCase__      ,				lowerCAmelCase__      :      Dict         =		array[smallest], array[idx]
													(
													    (
													    lowerCAmelCase__
													)      ,				(
													    lowerCAmelCase__
													)      ,				
													)      :      List[Any]         =		(
													    self.idx_of_element[array[smallest]],
													    self.idx_of_element[array[idx]],
													)
													lowerCAmelCase__      :      Tuple         =		smallest
										else:
													break






				def 							_lowerCamelCase		(						self					:      Optional[int]    ,     a					:      List[Any]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      List[Any]         =		self.get_parent_idx(a   )
							while p >= 0 and self.heap[p] > self.heap[idx]:
										lowerCAmelCase__      ,				lowerCAmelCase__      :      List[str]         =		self.heap[idx], self.heap[p]
										lowerCAmelCase__      ,				lowerCAmelCase__      :      Any         =		(
										    self.idx_of_element[self.heap[idx]],
										    self.idx_of_element[self.heap[p]],
										)
										lowerCAmelCase__      :      Union[str, Any]         =		p
										lowerCAmelCase__      :      Optional[int]         =		self.get_parent_idx(a   )






				def 							_lowerCamelCase		(						self					:      Optional[Any]   ):






							'''simple docstring'''







							return self.heap[0]






				def 							_lowerCamelCase		(						self					:      Dict   ):






							'''simple docstring'''







							lowerCAmelCase__      ,				lowerCAmelCase__      :      List[Any]         =		self.heap[-1], self.heap[0]
							lowerCAmelCase__      ,				lowerCAmelCase__      :      Tuple         =		(
							    self.idx_of_element[self.heap[-1]],
							    self.idx_of_element[self.heap[0]],
							)

							lowerCAmelCase__      :      List[str]         =		self.heap.pop()
							del self.idx_of_element[x]
							self.sift_down(0    ,     self.heap   )
							return x






				def 							_lowerCamelCase		(						self					:      Any    ,     a					:      Optional[Any]   ):






							'''simple docstring'''







							self.heap.append(a   )
							lowerCAmelCase__      :      Tuple         =		len(self.heap   ) - 1
							lowerCAmelCase__      :      Union[str, Any]         =		node.val
							self.sift_up(len(self.heap   ) - 1   )






				def 							_lowerCamelCase		(						self					:      Any   ):






							'''simple docstring'''







							return len(self.heap   ) == 0






				def 							_lowerCamelCase		(						self					:      Dict    ,     a					:      Optional[int]    ,     a					:      str   ):






							'''simple docstring'''







							assert (
							    self.heap[self.idx_of_element[node]].val > new_value
							), "newValue must be less that current value"
							lowerCAmelCase__      :      Optional[int]         =		new_value
							lowerCAmelCase__      :      Optional[Any]         =		new_value
							self.sift_up(self.idx_of_element[node]   )






lowerCamelCase__          =		Node("""R""", -1)
lowerCamelCase__          =		Node("""B""", 6)
lowerCamelCase__          =		Node("""A""", 3)
lowerCamelCase__          =		Node("""X""", 1)
lowerCamelCase__          =		Node("""E""", 4)

# Use one of these two ways to generate Min-Heap

# Generating Min-Heap from array
lowerCamelCase__          =		MinHeap([r, b, a, x, e])

# Generating Min-Heap by Insert method
# myMinHeap.insert(a)
# myMinHeap.insert(b)
# myMinHeap.insert(x)
# myMinHeap.insert(r)
# myMinHeap.insert(e)

# Before
print("""Min Heap - before decrease key""")
for i in my_min_heap.heap:
					print(i)

print("""Min Heap - After decrease key of node [B -> -17]""")
my_min_heap.decrease_key(b, -17)

# After
for i in my_min_heap.heap:
					print(i)

if __name__ == "__main__":
					import doctest

					doctest.testmod()

class      A__							:






				def __init__(						self					:      Dict    ,     a					:      list[int]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Union[str, Any]         =		len(a   )
							lowerCAmelCase__      :      Optional[Any]         =		[0] * len_array

							if len_array > 0:
										lowerCAmelCase__      :      List[Any]         =		array[0]

							for i in range(1    ,     a   ):
										lowerCAmelCase__      :      Optional[int]         =		self.prefix_sum[i - 1] + array[i]






				def 							_lowerCamelCase		(						self					:      int    ,     a					:      int    ,     a					:      int   ):






							'''simple docstring'''







							if start == 0:
										return self.prefix_sum[end]

							return self.prefix_sum[end] - self.prefix_sum[start - 1]






				def 							_lowerCamelCase		(						self					:      Optional[Any]    ,     a					:      int   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Any         =		{0}
							for sum_item in self.prefix_sum:
										if sum_item - target_sum in sums:
													return True

										sums.add(a   )

							return False


if __name__ == "__main__":
					import doctest

					doctest.testmod()