


from math import sqrt






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and (
		    number >= 0
		), "'number' must been an int and positive"

		lowerCAmelCase__       :      Union[str, Any]   					= True

		# 0 and 1 are none primes.
		if number <= 1:
				lowerCAmelCase__       :      str   					= False

		for divisor in range(2     ,       int(round(sqrt(_a	)	)	) + 1	):
				# if 'number' divisible by 'divisor' then sets 'status'
				# of false and break up the loop.
				if number % divisor == 0:
						lowerCAmelCase__       :      Any   					= False
						break

    # precondition
		assert isinstance(_a     ,       _a	), "'status' must been from type bool"

		return status






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and (n > 2), "'N' must been an int and > 2"

		# beginList: contains all natural numbers from 2 up to N
		lowerCAmelCase__       :      Optional[Any]   					= list(range(2     ,       n + 1	)	)

		lowerCAmelCase__       :      List[Any]   					= []  # this list will be returns.

		# actual sieve of erathostenes
		for i in range(len(_a	)	):
				for j in range(i + 1     ,       len(_a	)	):
						if (begin_list[i] != 0) and (begin_list[j] % begin_list[i] == 0):
								lowerCAmelCase__       :      int   					= 0

    # filters actual prime numbers.
		lowerCAmelCase__       :      Dict   					= [x for x in begin_list if x != 0]

		# precondition
		assert isinstance(_a     ,       _a	), "'ans' must been from type list"

		return ans






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and (n > 2), "'N' must been an int and > 2"

		lowerCAmelCase__       :      str   					= []

		# iterates over all numbers between 2 up to N+1
		# if a number is prime then appends to list 'ans'
		for number in range(2     ,       n + 1	):
				if is_prime(_a	):
						ans.append(_a	)

    # precondition
		assert isinstance(_a     ,       _a	), "'ans' must been from type list"

		return ans






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and number >= 0, "'number' must been an int and >= 0"

		lowerCAmelCase__       :      Optional[int]   					= []  # this list will be returns of the function.

		# potential prime number factors.

		lowerCAmelCase__       :      Optional[Any]   					= 2

		lowerCAmelCase__       :      List[str]   					= number

		if number == 0 or number == 1:
				ans.append(_a	)

		# if 'number' not prime then builds the prime factorization of 'number'
		elif not is_prime(_a	):
				while quotient != 1:
						if is_prime(_a	) and (quotient % factor == 0):
								ans.append(_a	)
								quotient /= factor
						else:
								factor += 1

		else:
				ans.append(_a	)

		# precondition
		assert isinstance(_a     ,       _a	), "'ans' must been from type list"

		return ans






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and (
		    number >= 0
		), "'number' bust been an int and >= 0"

		lowerCAmelCase__       :      Any   					= 0

		# prime factorization of 'number'
		lowerCAmelCase__       :      List[str]   					= prime_factorization(_a	)

		lowerCAmelCase__       :      int   					= max(_a	)

		# precondition
		assert isinstance(_a     ,       _a	), "'ans' must been from type int"

		return ans






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and (
		    number >= 0
		), "'number' bust been an int and >= 0"

		lowerCAmelCase__       :      Union[str, Any]   					= 0

		# prime factorization of 'number'
		lowerCAmelCase__       :      Dict   					= prime_factorization(_a	)

		lowerCAmelCase__       :      Any   					= min(_a	)

		# precondition
		assert isinstance(_a     ,       _a	), "'ans' must been from type int"

		return ans






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	), "'number' must been an int"
		assert isinstance(number % 2 == 0     ,       _a	), "compare bust been from type bool"

		return number % 2 == 0






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	), "'number' must been an int"
		assert isinstance(number % 2 != 0     ,       _a	), "compare bust been from type bool"

		return number % 2 != 0






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert (
		    isinstance(_a     ,       _a	) and (number > 2) and is_even(_a	)
		), "'number' must been an int, even and > 2"

		lowerCAmelCase__       :      str   					= []  # this list will returned

		# creates a list of prime numbers between 2 up to 'number'
		lowerCAmelCase__       :      int   					= get_prime_numbers(_a	)
		lowerCAmelCase__       :      List[str]   					= len(_a	)

		# run variable for while-loops.
		lowerCAmelCase__       :      int   					= 0
		lowerCAmelCase__       :      Dict   					= None

		# exit variable. for break up the loops
		lowerCAmelCase__       :      List[str]   					= True

		while i < len_pn and loop:
				lowerCAmelCase__       :      Any   					= i + 1

				while j < len_pn and loop:
						if prime_numbers[i] + prime_numbers[j] == number:
								lowerCAmelCase__       :      Dict   					= False
								ans.append(prime_numbers[i]	)
								ans.append(prime_numbers[j]	)

						j += 1

				i += 1

		# precondition
		assert (
		    isinstance(_a     ,       _a	)
		    and (len(_a	) == 2)
		    and (ans[0] + ans[1] == number)
		    and is_prime(ans[0]	)
		    and is_prime(ans[1]	)
		), "'ans' must contains two primes. And sum of elements must been eq 'number'"

		return ans






def 					lowerCamelCase_   (	_a     ,       _a	):




		"""simple docstring"""






		assert (
		    isinstance(_a     ,       _a	)
		    and isinstance(_a     ,       _a	)
		    and (numbera >= 0)
		    and (numbera >= 0)
		), "'number1' and 'number2' must been positive integer."

		lowerCAmelCase__       :      Optional[int]   					= 0

		while numbera != 0:
				lowerCAmelCase__       :      Union[str, Any]   					= numbera % numbera
				lowerCAmelCase__       :      int   					= numbera
				lowerCAmelCase__       :      Dict   					= rest

		# precondition
		assert isinstance(_a     ,       _a	) and (
		    numbera >= 0
		), "'number' must been from type int and positive"

		return numbera






def 					lowerCamelCase_   (	_a     ,       _a	):




		"""simple docstring"""






		assert (
		    isinstance(_a     ,       _a	)
		    and isinstance(_a     ,       _a	)
		    and (numbera >= 1)
		    and (numbera >= 1)
		), "'number1' and 'number2' must been positive integer."

		lowerCAmelCase__       :      Dict   					= 1  # actual answer that will be return.

		# for kgV (x,1)
		if numbera > 1 and numbera > 1:
				# builds the prime factorization of 'number1' and 'number2'
				lowerCAmelCase__       :      Optional[Any]   					= prime_factorization(_a	)
				lowerCAmelCase__       :      str   					= prime_factorization(_a	)

		elif numbera == 1 or numbera == 1:
				lowerCAmelCase__       :      Union[str, Any]   					= []
				lowerCAmelCase__       :      Tuple   					= []
				lowerCAmelCase__       :      int   					= max(_a     ,       _a	)

		lowerCAmelCase__       :      List[str]   					= 0
		lowerCAmelCase__       :      Optional[Any]   					= 0

		lowerCAmelCase__       :      List[str]   					= []  # captured numbers int both 'primeFac1' and 'primeFac2'

		# iterates through primeFac1
		for n in prime_fac_a:
				if n not in done:
						if n in prime_fac_a:
								lowerCAmelCase__       :      str   					= prime_fac_a.count(_a	)
								lowerCAmelCase__       :      Tuple   					= prime_fac_a.count(_a	)

								for _ in range(max(_a     ,       _a	)	):
										ans *= n

						else:
								lowerCAmelCase__       :      int   					= prime_fac_a.count(_a	)

								for _ in range(_a	):
										ans *= n

						done.append(_a	)

    # iterates through primeFac2
		for n in prime_fac_a:
				if n not in done:
						lowerCAmelCase__       :      Optional[int]   					= prime_fac_a.count(_a	)

						for _ in range(_a	):
								ans *= n

						done.append(_a	)

    # precondition
		assert isinstance(_a     ,       _a	) and (
		    ans >= 0
		), "'ans' must been from type int and positive"

		return ans






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and (n >= 0), "'number' must been a positive int"

		lowerCAmelCase__       :      Union[str, Any]   					= 0
		lowerCAmelCase__       :      Any   					= 2  # this variable holds the answer

		while index < n:
				index += 1

				ans += 1  # counts to the next number

				# if ans not prime then
				# runs to the next prime number.
				while not is_prime(_a	):
						ans += 1

    # precondition
		assert isinstance(_a     ,       _a	) and is_prime(
		    _a	), "'ans' must been a prime number and from type int"

		return ans






def 					lowerCamelCase_   (	_a     ,       _a	):




		"""simple docstring"""






		assert (
		    is_prime(_a	) and is_prime(_a	) and (p_number_a < p_number_a)
		), "The arguments must been prime numbers and 'pNumber1' < 'pNumber2'"

		lowerCAmelCase__       :      Optional[int]   					= p_number_a + 1  # jump to the next number

		lowerCAmelCase__       :      str   					= []  # this list will be returns.

		# if number is not prime then
		# fetch the next prime number.
		while not is_prime(_a	):
				number += 1

		while number < p_number_a:
				ans.append(_a	)

				number += 1

				# fetch the next prime number.
				while not is_prime(_a	):
						number += 1

    # precondition
		assert (
		    isinstance(_a     ,       _a	)
		    and ans[0] != p_number_a
		    and ans[len(_a	) - 1] != p_number_a
		), "'ans' must been a list without the arguments"

		# 'ans' contains not 'pNumber1' and 'pNumber2' !
		return ans






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and (n >= 1), "'n' must been int and >= 1"

		lowerCAmelCase__       :      int   					= []  # will be returned.

		for divisor in range(1     ,       n + 1	):
				if n % divisor == 0:
						ans.append(_a	)

    # precondition
		assert ans[0] == 1 and ans[len(_a	) - 1] == n, "Error in function getDivisiors(...)"

		return ans






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and (
		    number > 1
		), "'number' must been an int and >= 1"

		lowerCAmelCase__       :      Tuple   					= get_divisors(_a	)

		# precondition
		assert (
		    isinstance(_a     ,       _a	)
		    and (divisors[0] == 1)
		    and (divisors[len(_a	) - 1] == number)
		), "Error in help-function getDivisiors(...)"

		# summed all divisors up to 'number' (exclusive), hence [:-1]
		return sum(divisors[:-1]	) == number






def 					lowerCamelCase_   (	_a     ,       _a	):




		"""simple docstring"""






		assert (
		    isinstance(_a     ,       _a	)
		    and isinstance(_a     ,       _a	)
		    and (denominator != 0)
		), "The arguments must been from type int and 'denominator' != 0"

		# build the greatest common divisor of numerator and denominator.
		lowerCAmelCase__       :      List[str]   					= gcd(abs(_a	)     ,       abs(_a	)	)

		# precondition
		assert (
		    isinstance(_a     ,       _a	)
		    and (numerator % gcd_of_fraction == 0)
		    and (denominator % gcd_of_fraction == 0)
		), "Error in function gcd(...,...)"

		return (numerator // gcd_of_fraction, denominator // gcd_of_fraction)






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and (n >= 0), "'n' must been a int and >= 0"

		lowerCAmelCase__       :      Tuple   					= 1  # this will be return.

		for factor in range(1     ,       n + 1	):
				ans *= factor

		return ans






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		assert isinstance(_a     ,       _a	) and (n >= 0), "'n' must been an int and >= 0"

		lowerCAmelCase__       :      str   					= 0
		lowerCAmelCase__       :      Union[str, Any]   					= 1
		lowerCAmelCase__       :      List[Any]   					= 1  # this will be return

		for _ in range(n - 1	):
				lowerCAmelCase__       :      Optional[int]   					= ans
				ans += fiba
				lowerCAmelCase__       :      Any   					= tmp

		return ans








class  _a							:




	def __init__( self						:		str		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		List[Any]		)->	Tuple:
			lowerCAmelCase__       :      List[Any]   					= None
			lowerCAmelCase__       :      int   					= None
			lowerCAmelCase__       :      Union[str, Any]   					= graph

			self._normalize_graph(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      Tuple   					= len(_SCREAMING_SNAKE_CASE		)
			lowerCAmelCase__       :      Optional[int]   					= None




	def 							UpperCAmelCase__( self						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		)->	Union[str, Any]:
			if sources is int:
					lowerCAmelCase__       :      List[Any]   					= [sources]
			if sinks is int:
					lowerCAmelCase__       :      Optional[Any]   					= [sinks]

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

			lowerCAmelCase__       :      Union[str, Any]   					= sources[0]
			lowerCAmelCase__       :      Dict   					= sinks[0]

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

					lowerCAmelCase__       :      Any   					= len(self.graph		) + 1
					for room in self.graph:
							room.insert(0		, 0		)
					self.graph.insert(0		, [0] * size		)
					for i in sources:
							lowerCAmelCase__       :      Optional[Any]   					= max_input_flow
					lowerCAmelCase__       :      List[str]   					= 0

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




	def 							UpperCAmelCase__( self						:		Union[str, Any]		)->	Union[str, Any]:
			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						:		str		, _SCREAMING_SNAKE_CASE						:		List[Any]		)->	int:
			lowerCAmelCase__       :      int   					= algorithm(self		)





class  _a							:




	def __init__( self						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Tuple		)->	Union[str, Any]:
			lowerCAmelCase__       :      Tuple   					= flow_network
			lowerCAmelCase__       :      Dict   					= flow_network.verticesCount
			lowerCAmelCase__       :      Optional[Any]   					= flow_network.sourceIndex
			lowerCAmelCase__       :      Optional[Any]   					= flow_network.sinkIndex
			# it's just a reference, so you shouldn't change
			# it in your algorithms, use deep copy before doing that
			lowerCAmelCase__       :      str   					= flow_network.graph
			lowerCAmelCase__       :      Optional[int]   					= False




	def 							UpperCAmelCase__( self						:		List[str]		)->	Dict:
			if not self.executed:
					self._algorithm()
					lowerCAmelCase__       :      Any   					= True




	def 							UpperCAmelCase__( self						:		Optional[Any]		)->	int:
			pass





class  _a							(    _lowercase):




	def __init__( self						:		Any		, _SCREAMING_SNAKE_CASE						:		List[Any]		)->	Union[str, Any]:
			super().__init__(_SCREAMING_SNAKE_CASE		)
			# use this to save your result
			lowerCAmelCase__       :      Dict   					= -1




	def 							UpperCAmelCase__( self						:		Any		)->	Optional[Any]:
			if not self.executed:
					raise Exception('''You should execute algorithm before using its result!'''		)

			return self.maximum_flow





class  _a							(    _lowercase):




	def __init__( self						:		Any		, _SCREAMING_SNAKE_CASE						:		List[str]		)->	List[str]:
			super().__init__(_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      Any   					= [[0] * self.verticies_count for i in range(self.verticies_count		)]

			lowerCAmelCase__       :      Optional[Any]   					= [0] * self.verticies_count
			lowerCAmelCase__       :      str   					= [0] * self.verticies_count




	def 							UpperCAmelCase__( self						:		Any		)->	List[Any]:
			lowerCAmelCase__       :      Optional[Any]   					= 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
			lowerCAmelCase__       :      Any   					= [
			    i
			    for i in range(self.verticies_count		)
			    if i != self.source_index and i != self.sink_index
			]

			# move through list
			lowerCAmelCase__       :      str   					= 0
			while i < len(_SCREAMING_SNAKE_CASE		):
					lowerCAmelCase__       :      Union[str, Any]   					= vertices_list[i]
					lowerCAmelCase__       :      Any   					= self.heights[vertex_index]
					self.process_vertex(_SCREAMING_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(_SCREAMING_SNAKE_CASE		)		)
							lowerCAmelCase__       :      Optional[Any]   					= 0
					else:
							i += 1

			lowerCAmelCase__       :      Optional[Any]   					= sum(self.preflow[self.source_index]		)




	def 							UpperCAmelCase__( self						:		List[str]		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		)->	Optional[int]:
			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(_SCREAMING_SNAKE_CASE		, _SCREAMING_SNAKE_CASE		)

					self.relabel(_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		int		, _SCREAMING_SNAKE_CASE						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		)->	Union[str, Any]:
			lowerCAmelCase__       :      Union[str, Any]   					= 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						:		Optional[int]		, _SCREAMING_SNAKE_CASE						:		Any		)->	Optional[int]:
			lowerCAmelCase__       :      Optional[int]   					= 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):
							lowerCAmelCase__       :      List[Any]   					= self.heights[to_index]

			if min_height is not None:
					lowerCAmelCase__       :      Optional[Any]   					= min_height + 1


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

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

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




