


'''simple docstring'''






import string

import numpy





def      UpperCAmelCase      (		lowerCamelCase_  :int				,      lowerCamelCase_  :int ):







		'''simple docstring'''
		return b if a == 0 else greatest_common_divisor(b % a				,      lowerCamelCase_ )
class 						__UpperCamelCase	:
							lowercase			:		Optional[int]   		=  string.ascii_uppercase + string.digits
							# This cipher takes alphanumerics into account
							# i.e. a total of 36 characters

							# take x and return x % len(key_string)
							lowercase			:		Optional[int]   		=  numpy.vectorize(lambda lowercase__							: x % 3_6							)

							lowercase			:		List[Any]   		=  numpy.vectorize(lowercase__							)





							def __init__(  self		:Optional[int]  ,_UpperCamelCase		:numpy.ndarray			):
									snake_case_		:							Union[str, Any]			       =						self.modulus(_UpperCamelCase			)  # mod36 calc's on the encrypt key
									self.check_determinant()  # validate the determinant of the encryption key
									snake_case_		:							Optional[int]			       =						encrypt_key.shape[0]





							def 		a__   (  self		:List[Any]  ,_UpperCamelCase		:str			):
									return self.key_string.index(_UpperCamelCase			)





							def 		a__   (  self		:Dict  ,_UpperCamelCase		:int			):
									return self.key_string[round(_UpperCamelCase			)]





							def 		a__   (  self		:Optional[Any]			):
									snake_case_		:							int			       =						round(numpy.linalg.det(self.encrypt_key			)			)

									if det < 0:
											snake_case_		:							Optional[int]			       =						det % len(self.key_string			)

									snake_case_		:							Optional[Any]			       =						len(self.key_string			)
									if greatest_common_divisor(_UpperCamelCase  ,len(self.key_string			)			) != 1:
											snake_case_		:							List[str]			       =						(
											    F'''determinant modular {req_l} of encryption key({det}) '''
											    F'''is not co prime w.r.t {req_l}.\nTry another key.'''
											)
											raise ValueError(_UpperCamelCase			)





							def 		a__   (  self		:str  ,_UpperCamelCase		:str			):
									snake_case_		:							str			       =						[char for char in text.upper() if char in self.key_string]

									snake_case_		:							Union[str, Any]			       =						chars[-1]
									while len(_UpperCamelCase			) % self.break_key != 0:
											chars.append(_UpperCamelCase			)

									return "".join(_UpperCamelCase			)





							def 		a__   (  self		:List[str]  ,_UpperCamelCase		:str			):
									snake_case_		:							Optional[Any]			       =						self.process_text(text.upper()			)
									snake_case_		:							Dict			       =						""""""

									for i in range(0  ,len(_UpperCamelCase			) - self.break_key + 1  ,self.break_key			):
											snake_case_		:							Optional[Any]			       =						text[i : i + self.break_key]
											snake_case_		:							Any			       =						[self.replace_letters(_UpperCamelCase			) for char in batch]
											snake_case_		:							List[Any]			       =						numpy.array([vec]			).T
											snake_case_		:							Dict			       =						self.modulus(self.encrypt_key.dot(_UpperCamelCase			)			).T.tolist()[
											    0
											]
											snake_case_		:							str			       =						"""""".join(
											    self.replace_digits(_UpperCamelCase			) for num in batch_encrypted			)
											encrypted += encrypted_batch

									return encrypted





							def 		a__   (  self		:Union[str, Any]			):
									snake_case_		:							str			       =						round(numpy.linalg.det(self.encrypt_key			)			)

									if det < 0:
											snake_case_		:							int			       =						det % len(self.key_string			)
									snake_case_		:							Dict			       =						None
									for i in range(len(self.key_string			)			):
											if (det * i) % len(self.key_string			) == 1:
													snake_case_		:							Optional[Any]			       =						i
													break

									snake_case_		:							Union[str, Any]			       =						(
									    det_inv
									    * numpy.linalg.det(self.encrypt_key			)
									    * numpy.linalg.inv(self.encrypt_key			)
									)

									return self.to_int(self.modulus(_UpperCamelCase			)			)





							def 		a__   (  self		:List[Any]  ,_UpperCamelCase		:str			):
									snake_case_		:							List[str]			       =						self.make_decrypt_key()
									snake_case_		:							Tuple			       =						self.process_text(text.upper()			)
									snake_case_		:							Optional[int]			       =						""""""

									for i in range(0  ,len(_UpperCamelCase			) - self.break_key + 1  ,self.break_key			):
											snake_case_		:							Union[str, Any]			       =						text[i : i + self.break_key]
											snake_case_		:							List[str]			       =						[self.replace_letters(_UpperCamelCase			) for char in batch]
											snake_case_		:							Dict			       =						numpy.array([vec]			).T
											snake_case_		:							List[str]			       =						self.modulus(decrypt_key.dot(_UpperCamelCase			)			).T.tolist()[0]
											snake_case_		:							List[str]			       =						"""""".join(
											    self.replace_digits(_UpperCamelCase			) for num in batch_decrypted			)
											decrypted += decrypted_batch

									return decrypted





def      UpperCAmelCase      (		):







		'''simple docstring'''
		snake_case_		:							Dict			       =						int(input("""Enter the order of the encryption key: """ ) )
		snake_case_		:							Union[str, Any]			       =						[]

		print("""Enter each row of the encryption key with space separated integers""" )
		for _ in range(lowerCamelCase_ ):
				snake_case_		:							Any			       =						[int(lowerCamelCase_ ) for x in input().split()]
				hill_matrix.append(lowerCamelCase_ )

		snake_case_		:							str			       =						HillCipher(numpy.array(lowerCamelCase_ ) )

		print("""Would you like to encrypt or decrypt some text? (1 or 2)""" )
		snake_case_		:							int			       =						input("""\n1. Encrypt\n2. Decrypt\n""" )
		if option == "1":
				snake_case_		:							str			       =						input("""What text would you like to encrypt?: """ )
				print("""Your encrypted text is:""" )
				print(hc.encrypt(lowerCamelCase_ ) )
		elif option == "2":
				snake_case_		:							Dict			       =						input("""What text would you like to decrypt?: """ )
				print("""Your decrypted text is:""" )
				print(hc.decrypt(lowerCamelCase_ ) )


if __name__ == "__main__":
							import doctest

							doctest.testmod()

							main()



'''simple docstring'''






def      UpperCAmelCase      (		lowerCamelCase_  :Tuple				,      lowerCamelCase_  :Optional[Any]				,      lowerCamelCase_  :str				,      lowerCamelCase_  :str ):







		'''simple docstring'''
		# Return True if there is node that has not iterated.
		snake_case_		:							Optional[int]			       =						[False] * len(lowerCamelCase_ )
		snake_case_		:							Dict			       =						[]
		queue.append(lowerCamelCase_ )
		snake_case_		:							Tuple			       =						True

		while queue:
				snake_case_		:							Union[str, Any]			       =						queue.pop(0 )
				for ind in range(len(graph[u] ) ):
						if visited[ind] is False and graph[u][ind] > 0:
								queue.append(lowerCamelCase_ )
								snake_case_		:							str			       =						True
								snake_case_		:							Optional[Any]			       =						u

		return visited[t]





def      UpperCAmelCase      (		lowerCamelCase_  :Optional[Any]				,      lowerCamelCase_  :Dict				,      lowerCamelCase_  :Union[str, Any] ):







		'''simple docstring'''
		# This array is filled by BFS and to store path
		snake_case_		:							Optional[int]			       =						[-1] * (len(lowerCamelCase_ ))
		snake_case_		:							Tuple			       =						0
		while bfs(lowerCamelCase_				,      lowerCamelCase_				,      lowerCamelCase_				,      lowerCamelCase_ ):
				snake_case_		:							int			       =						float("""Inf""" )
				snake_case_		:							Any			       =						sink

				while s != source:
						# Find the minimum value in select path
						snake_case_		:							Optional[Any]			       =						min(lowerCamelCase_				,      graph[parent[s]][s] )
						snake_case_		:							Union[str, Any]			       =						parent[s]

				max_flow += path_flow
				snake_case_		:							Dict			       =						sink

				while v != source:
						snake_case_		:							Optional[int]			       =						parent[v]
						graph[u][v] -= path_flow
						graph[v][u] += path_flow
						snake_case_		:							Any			       =						parent[v]
		return max_flow


__A	:	Union[str, Any]     =     [
    [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],
]

__A,   __A	:	Union[str, Any]     =     0, 5






print(ford_fulkerson(graph, source, sink))