



from collections.abc import Sequence
from queue import Queue

class 					_A :



							def __init__(	self							:  Union[str, Any]  ,	__SCREAMING_SNAKE_CASE							:  Any  ,	__SCREAMING_SNAKE_CASE							:  List[Any]  ,	__SCREAMING_SNAKE_CASE							:  Tuple  ,	__SCREAMING_SNAKE_CASE							:  Dict=None  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]=None):


											'''simple docstring'''

											__a		 =       start
											__a		 =       end
											__a		 =       val
											__a		 =       (start + end) // 2
											__a		 =       left
											__a		 =       right





							def __repr__(	self							:  Optional[int]):


											'''simple docstring'''

											return F'SegmentTreeNode(start={self.start}, end={self.end}, val={self.val})'


class 					_A :



							def __init__(	self							:  Any  ,	__SCREAMING_SNAKE_CASE							:  Sequence  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]):


											'''simple docstring'''

											__a		 =       collection
											__a		 =       function
											if self.collection:
															__a		 =       self._build_tree(0  ,	len(lowercase_) - 1)



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


											'''simple docstring'''

											self._update_tree(self.root  ,	lowercase_  ,	lowercase_)



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


											'''simple docstring'''

											return self._query_range(self.root  ,	lowercase_  ,	lowercase_)



							def 	_lowerCamelCase    (	self							:  Optional[Any]  ,	__SCREAMING_SNAKE_CASE							:  Dict  ,	__SCREAMING_SNAKE_CASE							:  Tuple):


											'''simple docstring'''

											if start == end:
															return SegmentTreeNode(lowercase_  ,	lowercase_  ,	self.collection[start])
											__a		 =       (start + end) // 2
											__a		 =       self._build_tree(lowercase_  ,	lowercase_)
											__a		 =       self._build_tree(mid + 1  ,	lowercase_)
											return SegmentTreeNode(lowercase_  ,	lowercase_  ,	self.fn(left.val  ,	right.val)  ,	lowercase_  ,	lowercase_)



							def 	_lowerCamelCase    (	self							:  str  ,	__SCREAMING_SNAKE_CASE							:  Dict  ,	__SCREAMING_SNAKE_CASE							:  List[Any]  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]):


											'''simple docstring'''

											if node.start == i and node.end == i:
															__a		 =       val
															return
											if i <= node.mid:
															self._update_tree(node.left  ,	lowercase_  ,	lowercase_)
											else:
															self._update_tree(node.right  ,	lowercase_  ,	lowercase_)
											__a		 =       self.fn(node.left.val  ,	node.right.val)



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


											'''simple docstring'''

											if node.start == i and node.end == j:
															return node.val

											if i <= node.mid:
															if j <= node.mid:
																			# range in left child tree
																			return self._query_range(node.left  ,	lowercase_  ,	lowercase_)
															else:
																			# range in left child tree and right child tree
																			return self.fn(
																			    self._query_range(node.left  ,	lowercase_  ,	node.mid)  ,	self._query_range(node.right  ,	node.mid + 1  ,	lowercase_)  ,	)
											else:
															# range in right child tree
															return self._query_range(node.right  ,	lowercase_  ,	lowercase_)





							def 	_lowerCamelCase    (	self							:  Any):


											'''simple docstring'''

											if self.root is not None:
															__a		 =       Queue()
															queue.put(self.root)
															while not queue.empty():
																			__a		 =       queue.get()
																			yield node

																			if node.left is not None:
																							queue.put(node.left)

																			if node.right is not None:
																							queue.put(node.right)


if __name__ == "__main__":
	import operator

	for fn in [operator.add, max, min]:
		print('''*''' * 50)
		__snake_case		:Optional[int]   	=  SegmentTree([2, 1, 5, 3, 4], fn)
		for node in arr.traverse():
			print(node)
		print()

		arr.update(1, 5)
		for node in arr.traverse():
			print(node)
		print()

		print(arr.query_range(3, 4))  # 7
		print(arr.query_range(2, 2))  # 5
		print(arr.query_range(1, 3))  # 13
		print()










__snake_case		:str   	=  [
    [0, 16, 13, 0, 0, 0],
    [0, 0, 10, 12, 0, 0],
    [0, 4, 0, 0, 14, 0],
    [0, 0, 9, 0, 0, 20],
    [0, 0, 0, 7, 0, 4],
    [0, 0, 0, 0, 0, 0],
]





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase       ):
    # Return True if there is node that has not iterated.
    __a		 =       [False] * len(_UpperCAmelCase       )
    __a		 =       [s]
    __a		 =       True

    while queue:
        __a		 =       queue.pop(0       )
        for ind in range(len(graph[u]       )       ):
            if visited[ind] is False and graph[u][ind] > 0:
                queue.append(_UpperCAmelCase       )
                __a		 =       True
                __a		 =       u

    return visited[t]





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase       ):
    __a		 =       [-1] * (len(_UpperCAmelCase       ))
    __a		 =       0
    __a		 =       []
    __a		 =       [i[:] for i in graph]  # Record original cut, copy.
    while bfs(_UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase       ):
        __a		 =       float('''Inf'''       )
        __a		 =       sink

        while s != source:
            # Find the minimum value in select path
            __a		 =       min(_UpperCAmelCase     ,				graph[parent[s]][s]       )
            __a		 =       parent[s]

        max_flow += path_flow
        __a		 =       sink

        while v != source:
            __a		 =       parent[v]
            graph[u][v] -= path_flow
            graph[v][u] += path_flow
            __a		 =       parent[v]

    for i in range(len(_UpperCAmelCase       )       ):
        for j in range(len(graph[0]       )       ):
            if graph[i][j] == 0 and temp[i][j] > 0:
                res.append((i, j)       )

    return res


if __name__ == "__main__":
 print(mincut(test_graph, source=0, sink=5))





