'''simple docstring'''




class 				a__:


			'''simple docstring'''






			def __init__(   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase):




					"""simple docstring"""


					lowerCAmelCase   					=  name
					lowerCAmelCase   					=  val



			def __str__(   self):




					"""simple docstring"""


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







			def __lt__(   self       ,    __lowerCAmelCase):




					"""simple docstring"""


					return self.val < other.val







class 				a__:


			'''simple docstring'''






			def __init__(   self       ,    __lowerCAmelCase):




					"""simple docstring"""


					lowerCAmelCase   					=  {}
					lowerCAmelCase   					=  {}
					lowerCAmelCase   					=  self.build_heap(__lowerCAmelCase)



			def __getitem__(   self       ,    __lowerCAmelCase):




					"""simple docstring"""


					return self.get_value(__lowerCAmelCase)



			def 							a_       (   self       ,    __lowerCAmelCase):




					"""simple docstring"""


					return (idx - 1) // 2



			def 							a_       (   self       ,    __lowerCAmelCase):




					"""simple docstring"""


					return idx * 2 + 1



			def 							a_       (   self       ,    __lowerCAmelCase):




					"""simple docstring"""


					return idx * 2 + 2



			def 							a_       (   self       ,    __lowerCAmelCase):




					"""simple docstring"""


					return self.heap_dict[key]



			def 							a_       (   self       ,    __lowerCAmelCase):




					"""simple docstring"""


					lowerCAmelCase   					=  len(__lowerCAmelCase) - 1
					lowerCAmelCase   					=  self.get_parent_idx(__lowerCAmelCase)

					for idx, i in enumerate(__lowerCAmelCase):
							lowerCAmelCase   					=  idx
							lowerCAmelCase   					=  i.val

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



			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase):




					"""simple docstring"""


					while True:
							lowerCAmelCase   					=  self.get_left_child_idx(__lowerCAmelCase)  # noqa: E741
							lowerCAmelCase   					=  self.get_right_child_idx(__lowerCAmelCase)

							lowerCAmelCase   					=  idx
							if l < len(__lowerCAmelCase) and array[l] < array[idx]:
									lowerCAmelCase   					=  l
							if r < len(__lowerCAmelCase) and array[r] < array[smallest]:
									lowerCAmelCase   					=  r

							if smallest != idx:
									lowerCAmelCase					,     lowerCAmelCase   					=  array[smallest], array[idx]
									(
									    (
									    lowerCAmelCase
									)					,     (
									    lowerCAmelCase
									)					,     
									)   					=  (
									    self.idx_of_element[array[smallest]],
									    self.idx_of_element[array[idx]],
									)
									lowerCAmelCase   					=  smallest
							else:
									break



			def 							a_       (   self       ,    __lowerCAmelCase):




					"""simple docstring"""


					lowerCAmelCase   					=  self.get_parent_idx(__lowerCAmelCase)
					while p >= 0 and self.heap[p] > self.heap[idx]:
							lowerCAmelCase					,     lowerCAmelCase   					=  self.heap[idx], self.heap[p]
							lowerCAmelCase					,     lowerCAmelCase   					=  (
							    self.idx_of_element[self.heap[idx]],
							    self.idx_of_element[self.heap[p]],
							)
							lowerCAmelCase   					=  p
							lowerCAmelCase   					=  self.get_parent_idx(__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					return self.heap[0]



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase					,     lowerCAmelCase   					=  self.heap[-1], self.heap[0]
					lowerCAmelCase					,     lowerCAmelCase   					=  (
					    self.idx_of_element[self.heap[-1]],
					    self.idx_of_element[self.heap[0]],
					)

					lowerCAmelCase   					=  self.heap.pop()
					del self.idx_of_element[x]
					self.sift_down(0       ,    self.heap)
					return x



			def 							a_       (   self       ,    __lowerCAmelCase):




					"""simple docstring"""


					self.heap.append(__lowerCAmelCase)
					lowerCAmelCase   					=  len(self.heap) - 1
					lowerCAmelCase   					=  node.val
					self.sift_up(len(self.heap) - 1)



			def 							a_       (   self):




					"""simple docstring"""


					return len(self.heap) == 0







			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase):




					"""simple docstring"""


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







__lowercase          =  Node('''R''', -1)
__lowercase          =  Node('''B''', 6)
__lowercase          =  Node('''A''', 3)
__lowercase          =  Node('''X''', 1)
__lowercase          =  Node('''E''', 4)

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

# Generating Min-Heap from array
__lowercase          =  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, -1_7)

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

if __name__ == "__main__":
						import doctest

						doctest.testmod()





'''simple docstring'''




def 				snake_case__							(			_A:					int      ,   _A:					int )    ->	int:

		'''simple docstring'''


		while a != 0:
				lowerCAmelCase					,     lowerCAmelCase   					=  b % a, a
		return b






def 				snake_case__							(			_A:					int      ,   _A:					int )    ->	int:

		'''simple docstring'''


		if gcd(_A      ,   _A ) != 1:
				lowerCAmelCase   					=  f"mod inverse of {a!r} and {m!r} does not exist"
				raise ValueError(_A )
		lowerCAmelCase					,     lowerCAmelCase					,     lowerCAmelCase   					=  1, 0, a
		lowerCAmelCase					,     lowerCAmelCase					,     lowerCAmelCase   					=  0, 1, m
		while va != 0:
				lowerCAmelCase   					=  ua // va
				lowerCAmelCase					,     lowerCAmelCase					,     lowerCAmelCase					,     lowerCAmelCase					,     lowerCAmelCase					,     lowerCAmelCase   					=  (ua - q * va), (ua - q * va), (ua - q * va), va, va, va
		return ua % m




