


"""simple docstring"""







from __future__ import annotations

import math


class       SCREAMING_SNAKE_CASE__				:
       """simple docstring"""


       def __init__(						self		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     Any								=							size
         # approximate the overall size of segment tree with given value
         lowerCAmelCase     :     Optional[int]								=							[0 for i in range(0		,     4 * size						)]
         # create array to store lazy update
         lowerCAmelCase     :     List[str]								=							[0 for i in range(0		,     4 * size						)]
         lowerCAmelCase     :     Dict								=							[0 for i in range(0		,     4 * size						)]  # flag for lazy update

       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         return idx * 2

       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         return idx * 2 + 1

       def        lowercase__							(						self		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         if left_element == right_element:
           lowerCAmelCase     :     List[str]								=							a[left_element - 1]
         else:
           lowerCAmelCase     :     Tuple								=							(left_element + right_element) // 2
           self.build(self.left(snake_case__						)		,     snake_case__		,     snake_case__		,     snake_case__						)
           self.build(self.right(snake_case__						)		,     mid + 1		,     snake_case__		,     snake_case__						)
           lowerCAmelCase     :     Tuple								=							max(
               self.segment_tree[self.left(snake_case__						)]		,     self.segment_tree[self.right(snake_case__						)]						)

       def        lowercase__							(						self		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         if self.flag[idx] is True:
           lowerCAmelCase     :     Optional[int]								=							self.lazy[idx]
           lowerCAmelCase     :     List[str]								=							False
           if left_element != right_element:
             lowerCAmelCase     :     Optional[Any]								=							self.lazy[idx]
             lowerCAmelCase     :     List[Any]								=							self.lazy[idx]
             lowerCAmelCase     :     List[Any]								=							True
             lowerCAmelCase     :     Optional[Any]								=							True

         if right_element < a or left_element > b:
           return True
         if left_element >= a and right_element <= b:
           lowerCAmelCase     :     str								=							val
           if left_element != right_element:
             lowerCAmelCase     :     Optional[Any]								=							val
             lowerCAmelCase     :     Union[str, Any]								=							val
             lowerCAmelCase     :     int								=							True
             lowerCAmelCase     :     int								=							True
           return True
         lowerCAmelCase     :     List[str]								=							(left_element + right_element) // 2
         self.update(self.left(snake_case__						)		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__						)
         self.update(self.right(snake_case__						)		,     mid + 1		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__						)
         lowerCAmelCase     :     Optional[int]								=							max(
             self.segment_tree[self.left(snake_case__						)]		,     self.segment_tree[self.right(snake_case__						)]						)
         return True

       def        lowercase__							(						self		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         if self.flag[idx] is True:
           lowerCAmelCase     :     List[Any]								=							self.lazy[idx]
           lowerCAmelCase     :     str								=							False
           if left_element != right_element:
             lowerCAmelCase     :     Tuple								=							self.lazy[idx]
             lowerCAmelCase     :     List[Any]								=							self.lazy[idx]
             lowerCAmelCase     :     Optional[int]								=							True
             lowerCAmelCase     :     str								=							True
         if right_element < a or left_element > b:
           return -math.inf
         if left_element >= a and right_element <= b:
           return self.segment_tree[idx]
         lowerCAmelCase     :     Any								=							(left_element + right_element) // 2
         lowerCAmelCase     :     Optional[int]								=							self.query(self.left(snake_case__						)		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__						)
         lowerCAmelCase     :     Dict								=							self.query(self.right(snake_case__						)		,     mid + 1		,     snake_case__		,     snake_case__		,     snake_case__						)
         return max(snake_case__		,     snake_case__						)







       def __str__(						self						):






         """simple docstring"""





         return str([self.query(1		,     1		,     self.size		,     snake_case__		,     snake_case__						) for i in range(1		,     self.size + 1						)]						)


if __name__ == "__main__":
     lowerCAmelCase__      				=   [1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
     lowerCAmelCase__      				=   15
     lowerCAmelCase__      				=   SegmentTree(size)
     segt.build(1, 1, size, A)
     print(segt.query(1, 1, size, 4, 6))
     print(segt.query(1, 1, size, 7, 11))
     print(segt.query(1, 1, size, 7, 12))
     segt.update(1, 1, size, 1, 3, 111)
     print(segt.query(1, 1, size, 1, 15))
     segt.update(1, 1, size, 7, 8, 235)
     print(segt)







from collections import defaultdict

from graphs.minimum_spanning_tree_prims import prisms_algorithm as mst





def 			lowerCamelCase_ (				):
				lowerCamelCase_	,    lowerCamelCase_						=			9, 1_4  # noqa: F841
				lowerCamelCase_						=			[
				    [0, 1, 4],
				    [0, 7, 8],
				    [1, 2, 8],
				    [7, 8, 7],
				    [7, 6, 1],
				    [2, 8, 2],
				    [8, 6, 6],
				    [2, 3, 7],
				    [2, 5, 4],
				    [6, 5, 2],
				    [3, 5, 1_4],
				    [3, 4, 9],
				    [5, 4, 1_0],
				    [1, 7, 1_1],
				]

				lowerCamelCase_						=			defaultdict(lowerCamelCase__    )
				for nodea, nodea, cost in edges:
								adjancency[nodea].append([nodea, cost]    )
								adjancency[nodea].append([nodea, cost]    )

				lowerCamelCase_						=			mst(lowerCamelCase__    )

				lowerCamelCase_						=			[
				    [7, 6, 1],
				    [2, 8, 2],
				    [6, 5, 2],
				    [0, 1, 4],
				    [2, 5, 4],
				    [2, 3, 7],
				    [0, 7, 8],
				    [3, 4, 9],
				]

				for answer in expected:
								lowerCamelCase_						=			tuple(answer[:2]    )
								lowerCamelCase_						=			tuple(edge[::-1]    )
								assert edge in result or reverse in result


