


'''simple docstring'''






import logging
import os
import threading
import time


try:
							import warnings
except ImportError:
							__A	:	Dict     =     None

try:
							import msvcrt
except ImportError:
							__A	:	Any     =     None

try:
							import fcntl
except ImportError:
							__A	:	Dict     =     None


# Backward compatibility
# ------------------------------------------------
try:
							TimeoutError
except NameError:
							__A	:	List[Any]     =     OSError


# Data
# ------------------------------------------------
__A	:	Optional[Any]     =     [
    'Timeout',
    'BaseFileLock',
    'WindowsFileLock',
    'UnixFileLock',
    'SoftFileLock',
    'FileLock',
]

__A	:	Any     =     '3.0.12'


__A	:	Optional[Any]     =     None





def      UpperCAmelCase      (		):







		'''simple docstring'''
		global _logger
		snake_case_		:							int			       =						_logger or logging.getLogger(__name__ )
		return _logger
class 						__UpperCamelCase	(						lowercase__							):





							def __init__(  self		:int  ,_UpperCamelCase		:str			):
									snake_case_		:							List[Any]			       =						lock_file
									return None





							def __str__(  self		:Dict			):
									snake_case_		:							str			       =						F'''The file lock \'{self.lock_file}\' could not be acquired.'''
									return temp





class 						__UpperCamelCase	:





							def __init__(  self		:int  ,_UpperCamelCase		:str			):
									snake_case_		:							List[str]			       =						lock
									return None





							def __enter__(  self		:Union[str, Any]			):
									return self.lock





							def __exit__(  self		:Union[str, Any]  ,_UpperCamelCase		:List[Any]  ,_UpperCamelCase		:Optional[int]  ,_UpperCamelCase		:Optional[int]			):
									self.lock.release()
									return None





class 						__UpperCamelCase	:





							def __init__(  self		:str  ,_UpperCamelCase		:Optional[int]  ,_UpperCamelCase		:int=-1  ,_UpperCamelCase		:Tuple=None			):
									snake_case_		:							Union[str, Any]			       =						max_filename_length if max_filename_length is not None else 2_5_5
									# Hash the filename if it's too long
									snake_case_		:							Optional[int]			       =						self.hash_filename_if_too_long(_UpperCamelCase  ,_UpperCamelCase			)
									# The path to the lock file.
									snake_case_		:							str			       =						lock_file

									# The file descriptor for the *_lock_file* as it is returned by the
									# os.open() function.
									# This file lock is only NOT None, if the object currently holds the
									# lock.
									snake_case_		:							List[str]			       =						None

									# The default timeout value.
									snake_case_		:							Dict			       =						timeout

									# We use this lock primarily for the lock counter.
									snake_case_		:							List[Any]			       =						threading.Lock()

									# The lock counter is used for implementing the nested locking
									# mechanism. Whenever the lock is acquired, the counter is increased and
									# the lock is only released, when this value is 0 again.
									snake_case_		:							Tuple			       =						0
									return None





							@property
							def 		a__   (  self		:List[Any]			):
									return self._lock_file





							@property
							def 		a__   (  self		:Union[str, Any]			):
									return self._timeout





							@timeout.setter
							def 		a__   (  self		:Tuple  ,_UpperCamelCase		:Union[str, Any]			):
									snake_case_		:							Optional[Any]			       =						float(_UpperCamelCase			)
									return None





							def 		a__   (  self		:Dict			):
									raise NotImplementedError()





							def 		a__   (  self		:Union[str, Any]			):
									raise NotImplementedError()





							@property
							def 		a__   (  self		:str			):
									return self._lock_file_fd is not None





							def 		a__   (  self		:Tuple  ,_UpperCamelCase		:Dict=None  ,_UpperCamelCase		:Optional[Any]=0.05			):
									# Use the default timeout, if no timeout is provided.
									if timeout is None:
											snake_case_		:							List[Any]			       =						self.timeout

									# Increment the number right at the beginning.
									# We can still undo it, if something fails.
									with self._thread_lock:
											self._lock_counter += 1

									snake_case_		:							Dict			       =						id(self			)
									snake_case_		:							Tuple			       =						self._lock_file
									snake_case_		:							List[str]			       =						time.time()
									try:
											while True:
													with self._thread_lock:
															if not self.is_locked:
																	logger().debug(F'''Attempting to acquire lock {lock_id} on {lock_filename}'''			)
																	self._acquire()

													if self.is_locked:
															logger().debug(F'''Lock {lock_id} acquired on {lock_filename}'''			)
															break
													elif timeout >= 0 and time.time() - start_time > timeout:
															logger().debug(F'''Timeout on acquiring lock {lock_id} on {lock_filename}'''			)
															raise Timeout(self._lock_file			)
													else:
															logger().debug(
															    F'''Lock {lock_id} not acquired on {lock_filename}, waiting {poll_intervall} seconds ...'''			)
															time.sleep(_UpperCamelCase			)
									except:  # noqa
											# Something did go wrong, so decrement the counter.
											with self._thread_lock:
													snake_case_		:							Tuple			       =						max(0  ,self._lock_counter - 1			)

											raise
									return _Acquire_ReturnProxy(lock=self			)





							def 		a__   (  self		:str  ,_UpperCamelCase		:Optional[Any]=False			):
									with self._thread_lock:
											if self.is_locked:
													self._lock_counter -= 1

													if self._lock_counter == 0 or force:
															snake_case_		:							Optional[Any]			       =						id(self			)
															snake_case_		:							List[Any]			       =						self._lock_file

															logger().debug(F'''Attempting to release lock {lock_id} on {lock_filename}'''			)
															self._release()
															snake_case_		:							Optional[int]			       =						0
															logger().debug(F'''Lock {lock_id} released on {lock_filename}'''			)

									return None





							def __enter__(  self		:List[str]			):
									self.acquire()
									return self





							def __exit__(  self		:int  ,_UpperCamelCase		:Optional[int]  ,_UpperCamelCase		:Any  ,_UpperCamelCase		:Any			):
									self.release()
									return None





							def __del__(  self		:str			):
									self.release(force=_UpperCamelCase			)
									return None





							def 		a__   (  self		:List[Any]  ,_UpperCamelCase		:str  ,_UpperCamelCase		:int			):
									snake_case_		:							List[Any]			       =						os.path.basename(_UpperCamelCase			)
									if len(_UpperCamelCase			) > max_length and max_length > 0:
											snake_case_		:							List[str]			       =						os.path.dirname(_UpperCamelCase			)
											snake_case_		:							Optional[Any]			       =						str(hash(_UpperCamelCase			)			)
											snake_case_		:							Optional[Any]			       =						filename[: max_length - len(_UpperCamelCase			) - 8] + """...""" + hashed_filename + """.lock"""
											return os.path.join(_UpperCamelCase  ,_UpperCamelCase			)
									else:
											return path





class 						__UpperCamelCase	(						lowercase__							):





							def __init__(  self		:Tuple  ,_UpperCamelCase		:Tuple  ,_UpperCamelCase		:int=-1  ,_UpperCamelCase		:List[str]=None			):
									from .file_utils import relative_to_absolute_path

									super().__init__(_UpperCamelCase  ,timeout=_UpperCamelCase  ,max_filename_length=_UpperCamelCase			)
									snake_case_		:							Any			       =						"""\\\\?\\""" + relative_to_absolute_path(self.lock_file			)





							def 		a__   (  self		:List[str]			):
									snake_case_		:							List[Any]			       =						os.O_RDWR | os.O_CREAT | os.O_TRUNC

									try:
											snake_case_		:							Tuple			       =						os.open(self._lock_file  ,_UpperCamelCase			)
									except OSError:
											pass
									else:
											try:
													msvcrt.locking(_UpperCamelCase  ,msvcrt.LK_NBLCK  ,1			)
											except OSError:
													os.close(_UpperCamelCase			)
											else:
													snake_case_		:							str			       =						fd
									return None





							def 		a__   (  self		:Dict			):
									snake_case_		:							List[Any]			       =						self._lock_file_fd
									snake_case_		:							Optional[Any]			       =						None
									msvcrt.locking(_UpperCamelCase  ,msvcrt.LK_UNLCK  ,1			)
									os.close(_UpperCamelCase			)

									try:
											os.remove(self._lock_file			)
									# Probably another instance of the application
									# that acquired the file lock.
									except OSError:
											pass
									return None





class 						__UpperCamelCase	(						lowercase__							):





							def __init__(  self		:Optional[Any]  ,_UpperCamelCase		:Union[str, Any]  ,_UpperCamelCase		:Optional[Any]=-1  ,_UpperCamelCase		:int=None			):
									snake_case_		:							List[str]			       =						os.statvfs(os.path.dirname(_UpperCamelCase			)			).f_namemax
									super().__init__(_UpperCamelCase  ,timeout=_UpperCamelCase  ,max_filename_length=_UpperCamelCase			)





							def 		a__   (  self		:Optional[int]			):
									snake_case_		:							Dict			       =						os.O_RDWR | os.O_CREAT | os.O_TRUNC
									snake_case_		:							Optional[int]			       =						os.open(self._lock_file  ,_UpperCamelCase			)

									try:
											fcntl.flock(_UpperCamelCase  ,fcntl.LOCK_EX | fcntl.LOCK_NB			)
									except OSError:
											os.close(_UpperCamelCase			)
									else:
											snake_case_		:							Optional[int]			       =						fd
									return None





							def 		a__   (  self		:Union[str, Any]			):
									# Do not remove the lockfile:
									#
									#   https://github.com/benediktschmitt/py-filelock/issues/31
									#   https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
									snake_case_		:							str			       =						self._lock_file_fd
									snake_case_		:							Union[str, Any]			       =						None
									fcntl.flock(_UpperCamelCase  ,fcntl.LOCK_UN			)
									os.close(_UpperCamelCase			)
									return None





class 						__UpperCamelCase	(						lowercase__							):





							def 		a__   (  self		:Tuple			):
									snake_case_		:							List[str]			       =						os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
									try:
											snake_case_		:							Tuple			       =						os.open(self._lock_file  ,_UpperCamelCase			)
									except OSError:
											pass
									else:
											snake_case_		:							List[Any]			       =						fd
									return None





							def 		a__   (  self		:Any			):
									os.close(self._lock_file_fd			)
									snake_case_		:							Tuple			       =						None

									try:
											os.remove(self._lock_file			)
									# The file is already deleted and that's what we want.
									except OSError:
											pass
									return None





__A	:	Optional[int]     =     None

if msvcrt:
							__A	:	List[str]     =     WindowsFileLock
elif fcntl:
							__A	:	Optional[Any]     =     UnixFileLock
else:
							__A	:	List[str]     =     SoftFileLock

							if warnings is not None:
														warnings.warn('only soft file lock is available')



'''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))