




class 						__lowerCAmelCase      :
							def __init__(		self		:Optional[int]						, __magic_name__		:int						, __magic_name__		:Dict						, __magic_name__		:Optional[int]							):







								'''simple docstring'''







								a									=				None
								a									=				None
								a									=				graph

								self._normalize_graph(__snake_case						, __snake_case							)
								a									=				len(__snake_case							)
								a									=				None
							def  lowerCamelCase__				(		self		:Optional[int]						, __magic_name__		:List[Any]						, __magic_name__		:Tuple							):







								'''simple docstring'''







								if sources is int:
									a									=				[sources]
								if sinks is int:
									a									=				[sinks]

								if len(__snake_case							) == 0 or len(__snake_case							) == 0:
									return

								a									=				sources[0]
								a									=				sinks[0]

								# make fake vertex if there are more
								# than one source or sink
								if len(__snake_case							) > 1 or len(__snake_case							) > 1:
									a									=				0
									for i in sources:
										max_input_flow += sum(self.graph[i]							)

									a									=				len(self.graph							) + 1
									for room in self.graph:
										room.insert(0						, 0							)
									self.graph.insert(0						, [0] * size							)
									for i in sources:
										a									=				max_input_flow
									a									=				0

									a									=				len(self.graph							) + 1
									for room in self.graph:
										room.append(0							)
									self.graph.append([0] * size							)
									for i in sinks:
										a									=				max_input_flow
									a									=				size - 1
							def  lowerCamelCase__				(		self		:List[str]							):







								'''simple docstring'''







								if self.maximum_flow_algorithm is None:
									raise Exception("""You need to set maximum flow algorithm before."""							)
								if self.source_index is None or self.sink_index is None:
									return 0

								self.maximum_flow_algorithm.execute()
								return self.maximum_flow_algorithm.getMaximumFlow()





							def  lowerCamelCase__				(		self		:List[Any]						, __magic_name__		:int							):







								'''simple docstring'''







								a									=				algorithm(self							)







class 						__lowerCAmelCase      :
							def __init__(		self		:List[Any]						, __magic_name__		:Any							):







								'''simple docstring'''







								a									=				flow_network
								a									=				flow_network.verticesCount
								a									=				flow_network.sourceIndex
								a									=				flow_network.sinkIndex
								# it's just a reference, so you shouldn't change
								# it in your algorithms, use deep copy before doing that
								a									=				flow_network.graph
								a									=				False
							def  lowerCamelCase__				(		self		:Dict							):







								'''simple docstring'''







								if not self.executed:
									self._algorithm()
									a									=				True





							def  lowerCamelCase__				(		self		:Optional[Any]							):







								'''simple docstring'''







								pass







class 						__lowerCAmelCase      (      SCREAMING_SNAKE_CASE_					):
							def __init__(		self		:Any						, __magic_name__		:Any							):







								'''simple docstring'''







								super().__init__(__snake_case							)
								# use this to save your result
								a									=				-1





							def  lowerCamelCase__				(		self		:Dict							):







								'''simple docstring'''







								if not self.executed:
									raise Exception("""You should execute algorithm before using its result!"""							)

								return self.maximum_flow







class 						__lowerCAmelCase      (      SCREAMING_SNAKE_CASE_					):
							def __init__(		self		:Union[str, Any]						, __magic_name__		:Dict							):







								'''simple docstring'''







								super().__init__(__snake_case							)

								a									=				[[0] * self.verticies_count for i in range(self.verticies_count							)]

								a									=				[0] * self.verticies_count
								a									=				[0] * self.verticies_count
							def  lowerCamelCase__				(		self		:Any							):







								'''simple docstring'''







								a									=				self.verticies_count

								# push some substance to graph
								for nextvertex_index, bandwidth in enumerate(self.graph[self.source_index]							):
									self.preflow[self.source_index][nextvertex_index] += bandwidth
									self.preflow[nextvertex_index][self.source_index] -= bandwidth
									self.excesses[nextvertex_index] += bandwidth

								# Relabel-to-front selection rule
								a									=				[
								    i
								    for i in range(self.verticies_count							)
								    if i != self.source_index and i != self.sink_index
								]

								# move through list
								a									=				0
								while i < len(__snake_case							):
									a									=				vertices_list[i]
									a									=				self.heights[vertex_index]
									self.process_vertex(__snake_case							)
									if self.heights[vertex_index] > previous_height:
										# if it was relabeled, swap elements
										# and start from 0 index
										vertices_list.insert(0						, vertices_list.pop(__snake_case							)							)
										a									=				0
									else:
										i += 1

								a									=				sum(self.preflow[self.source_index]							)
							def  lowerCamelCase__				(		self		:List[Any]						, __magic_name__		:str							):







								'''simple docstring'''







								while self.excesses[vertex_index] > 0:
									for neighbour_index in range(self.verticies_count							):
										# if it's neighbour and current vertex is higher
										if (
										    self.graph[vertex_index][neighbour_index]
										    - self.preflow[vertex_index][neighbour_index]
										    > 0
										    and self.heights[vertex_index] > self.heights[neighbour_index]
										):
											self.push(__snake_case						, __snake_case							)

									self.relabel(__snake_case							)
							def  lowerCamelCase__				(		self		:Optional[Any]						, __magic_name__		:int						, __magic_name__		:Optional[int]							):







								'''simple docstring'''







								a									=				min(
								    self.excesses[from_index]						, self.graph[from_index][to_index] - self.preflow[from_index][to_index]						, )
								self.preflow[from_index][to_index] += preflow_delta
								self.preflow[to_index][from_index] -= preflow_delta
								self.excesses[from_index] -= preflow_delta
								self.excesses[to_index] += preflow_delta





							def  lowerCamelCase__				(		self		:List[Any]						, __magic_name__		:List[str]							):







								'''simple docstring'''







								a									=				None
								for to_index in range(self.verticies_count							):
									if (
									    self.graph[vertex_index][to_index]
									    - self.preflow[vertex_index][to_index]
									    > 0
									) and (min_height is None or self.heights[to_index] < min_height):
										a									=				self.heights[to_index]

								if min_height is not None:
									a									=				min_height + 1


if __name__ == "__main__":
		__UpperCamelCase   :			Optional[int]          = [0]
		__UpperCamelCase   :			Optional[int]          = [3]
		# graph = [
		#     [0, 0, 4, 6, 0, 0],
		#     [0, 0, 5, 2, 0, 0],
		#     [0, 0, 0, 0, 4, 4],
		#     [0, 0, 0, 0, 6, 6],
		#     [0, 0, 0, 0, 0, 0],
		#     [0, 0, 0, 0, 0, 0],
		# ]
		__UpperCamelCase   :			Union[str, Any]          = [[0, 7, 0, 0], [0, 0, 6, 0], [0, 0, 0, 8], [9, 0, 0, 0]]

		# prepare our network
		__UpperCamelCase   :			List[Any]          = FlowNetwork(graph, entrances, exits)
		# set algorithm
		flow_network.set_maximum_flow_algorithm(PushRelabelExecutor)
		# and calculate
		__UpperCamelCase   :			Any          = flow_network.find_maximum_flow()

		print(F'maximum flow is {maximum_flow}')









"""simple docstring"""





from __future__ import annotations



def   a    (     __UpperCAmelCase      :    list  )    ->							list:
						if len(__UpperCAmelCase  ) == 0:
												return []
						__magic_name__,			__magic_name__:	List[str]							=       min(__UpperCAmelCase  ), max(__UpperCAmelCase  )
						__magic_name__:	Optional[int]							=       int(max_value - min_value  ) + 1
						__magic_name__:	list[list]							=       [[] for _ in range(__UpperCAmelCase  )]

						for i in my_list:
												buckets[int(i - min_value  )].append(__UpperCAmelCase  )

						return [v for bucket in buckets for v in sorted(__UpperCAmelCase  )]


if __name__ == "__main__":
							from doctest import testmod

							testmod()
							assert bucket_sort([4, 5, 3, 2, 1]) == [1, 2, 3, 4, 5]
							assert bucket_sort([0, 1, -10, 15, 2, -2]) == [-10, -2, 0, 1, 2, 15]



