


class 							UpperCamelCase__ :

					def __init__(  self							: str				,       UpperCamelCase__							: int				,       UpperCamelCase__							: int				,       UpperCamelCase__							: int							):






										'''simple docstring'''






										lowercase_					=      None
										lowercase_					=      None
										lowercase_					=      graph

										self._normalize_graph(UpperCamelCase__				,       UpperCamelCase__							)
										lowercase_					=      len(UpperCamelCase__							)
										lowercase_					=      None

					def 	UpperCAmelCase__							(  self							: List[Any]				,       UpperCamelCase__							: Any				,       UpperCamelCase__							: Union[str, Any]							):






										'''simple docstring'''






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

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

										lowercase_					=      sources[0]
										lowercase_					=      sinks[0]

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

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

															lowercase_					=      len(self.graph							) + 1
															for room in self.graph:
																				room.append(0							)
															self.graph.append([0] * size							)
															for i in sinks:
																				lowercase_					=      max_input_flow
															lowercase_					=      size - 1

					def 	UpperCAmelCase__							(  self							: Any							):






										'''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 	UpperCAmelCase__							(  self							: Union[str, Any]				,       UpperCamelCase__							: int							):






										'''simple docstring'''






										lowercase_					=      algorithm(self							)







class 							UpperCamelCase__ :

					def __init__(  self							: Optional[int]				,       UpperCamelCase__							: List[str]							):






										'''simple docstring'''






										lowercase_					=      flow_network
										lowercase_					=      flow_network.verticesCount
										lowercase_					=      flow_network.sourceIndex
										lowercase_					=      flow_network.sinkIndex
										# it's just a reference, so you shouldn't change
										# it in your algorithms, use deep copy before doing that
										lowercase_					=      flow_network.graph
										lowercase_					=      False

					def 	UpperCAmelCase__							(  self							: Optional[int]							):






										'''simple docstring'''






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







					def 	UpperCAmelCase__							(  self							: Tuple							):






										'''simple docstring'''






										pass







class 							UpperCamelCase__ (						__A ):

					def __init__(  self							: Dict				,       UpperCamelCase__							: Optional[Any]							):






										'''simple docstring'''






										super().__init__(UpperCamelCase__							)
										# use this to save your result
										lowercase_					=      -1







					def 	UpperCAmelCase__							(  self							: Optional[Any]							):






										'''simple docstring'''






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

										return self.maximum_flow







class 							UpperCamelCase__ (						__A ):

					def __init__(  self							: str				,       UpperCamelCase__							: Dict							):






										'''simple docstring'''






										super().__init__(UpperCamelCase__							)

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

										lowercase_					=      [0] * self.verticies_count
										lowercase_					=      [0] * self.verticies_count

					def 	UpperCAmelCase__							(  self							: str							):






										'''simple docstring'''






										lowercase_					=      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
										lowercase_					=      [
										    i
										    for i in range(self.verticies_count							)
										    if i != self.source_index and i != self.sink_index
										]

										# move through list
										lowercase_					=      0
										while i < len(UpperCamelCase__							):
															lowercase_					=      vertices_list[i]
															lowercase_					=      self.heights[vertex_index]
															self.process_vertex(UpperCamelCase__							)
															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(UpperCamelCase__							)							)
																				lowercase_					=      0
															else:
																				i += 1

										lowercase_					=      sum(self.preflow[self.source_index]							)

					def 	UpperCAmelCase__							(  self							: str				,       UpperCamelCase__							: Optional[Any]							):






										'''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(UpperCamelCase__				,       UpperCamelCase__							)

															self.relabel(UpperCamelCase__							)

					def 	UpperCAmelCase__							(  self							: str				,       UpperCamelCase__							: str				,       UpperCamelCase__							: Any							):






										'''simple docstring'''






										lowercase_					=      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 	UpperCAmelCase__							(  self							: int				,       UpperCamelCase__							: Tuple							):






										'''simple docstring'''






										lowercase_					=      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):
																				lowercase_					=      self.heights[to_index]

										if min_height is not None:
															lowercase_					=      min_height + 1


if __name__ == "__main__":
							a       	=  [0]
							a       	=  [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],
							# ]
							a       	=  [[0, 7, 0, 0], [0, 0, 6, 0], [0, 0, 0, 8], [9, 0, 0, 0]]

							# prepare our network
							a       	=  FlowNetwork(graph, entrances, exits)
							# set algorithm
							flow_network.set_maximum_flow_algorithm(PushRelabelExecutor)
							# and calculate
							a       	=  flow_network.find_maximum_flow()

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










'''simple docstring'''







import math

import qiskit


def       __UpperCamelCase					(      lowercase_       :  int = 1   ,       lowercase_       :  int = 1   ,       lowercase_       :  int = 1   ):
       """simple docstring"""




       if (
           isinstance(lowercase_   ,       lowercase_   )
           or isinstance(lowercase_   ,       lowercase_   )
           or isinstance(lowercase_   ,       lowercase_   )
       ):
              raise TypeError('inputs must be integers.'   )

       if (input_a < 0) or (input_a < 0) or (carry_in < 0):
              raise ValueError('inputs must be positive.'   )

       if (
           (math.floor(lowercase_   ) != input_a)
           or (math.floor(lowercase_   ) != input_a)
           or (math.floor(lowercase_   ) != carry_in)
       ):
              raise ValueError('inputs must be exact integers.'   )

       if (input_a > 2) or (input_a > 2) or (carry_in > 2):
              raise ValueError('inputs must be less or equal to 2.'   )

       # build registers
       a_						     =			qiskit.QuantumRegister(4   ,       'qr'   )
       a_						     =			qiskit.ClassicalRegister(2   ,       'cr'   )
       # list the entries
       a_						     =			[input_a, input_a, carry_in]

       a_						     =			qiskit.QuantumCircuit(lowercase_   ,       lowercase_   )

       for i in range(0   ,       3   ):
              if entry[i] == 2:
                     quantum_circuit.h(lowercase_   )  # for hadamard entries
              elif entry[i] == 1:
                     quantum_circuit.x(lowercase_   )  # for 1 entries
              elif entry[i] == 0:
                     quantum_circuit.i(lowercase_   )  # for 0 entries

    # build the circuit
       quantum_circuit.ccx(0   ,       1   ,       3   )  # ccx = toffoli gate
       quantum_circuit.cx(0   ,       1   )
       quantum_circuit.ccx(1   ,       2   ,       3   )
       quantum_circuit.cx(1   ,       2   )
       quantum_circuit.cx(0   ,       1   )

       quantum_circuit.measure([2, 3]   ,       lowercase_   )  # measure the last two qbits

       a_						     =			qiskit.Aer.get_backend('aer_simulator'   )
       a_						     =			qiskit.execute(lowercase_   ,       lowercase_   ,       shots=1_000   )

       return job.result().get_counts(lowercase_   )


if __name__ == "__main__":
  print(f"""Total sum count for state is: {quantum_full_adder(1, 1, 1)}""")




