






from __future__ import annotations

from collections import deque
from queue import Queue
from timeit import timeit

_UpperCamelCase		:		int								=			{
    'A': ['B', 'C'],
    'B': ['A', 'D', 'E'],
    'C': ['A', 'F'],
    'D': ['B'],
    'E': ['B', 'F'],
    'F': ['C', 'E'],
}
def __UpperCAmelCase (			A			:	dict	,   A			:	str						)  -> Union[str, Any]:
			UpperCAmelCase_     :   Dict       =   {start}
			UpperCAmelCase_     :   int       =   [start]
			UpperCAmelCase_     :   Queue       =   Queue()
			queue.put(lowercase__						)
			while not queue.empty():
						UpperCAmelCase_     :   Union[str, Any]       =   queue.get()
						for w in graph[v]:
									if w not in explored:
												explored.add(lowercase__						)
												result.append(lowercase__						)
												queue.put(lowercase__						)
			return result
def __UpperCAmelCase (			A			:	dict	,   A			:	str						)  -> Optional[Any]:
			UpperCAmelCase_     :   Optional[Any]       =   {start}
			UpperCAmelCase_     :   List[str]       =   [start]
			UpperCAmelCase_     :   int       =   deque([start]						)
			while queue:
						UpperCAmelCase_     :   Optional[int]       =   queue.popleft()
						for child in graph[v]:
									if child not in visited:
												visited.add(lowercase__						)
												result.append(lowercase__						)
												queue.append(lowercase__						)
			return result
def __UpperCAmelCase (			A			:	str						)  -> Dict:
			UpperCAmelCase_     :   Dict       =   F"from __main__ import G, {name}"
			UpperCAmelCase_     :   Union[str, Any]       =   1_0_0_0_0
			UpperCAmelCase_     :   List[Any]       =   timeit(F"{name}(G, \'A\')"	,   setup=lowercase__	,   number=lowercase__						)
			print(F"{name:<35} finished {number} runs in {res:.5f} seconds"						)


if __name__ == "__main__":
						import doctest

						doctest.testmod()

						benchmark_function('breadth_first_search')
						benchmark_function('breadth_first_search_with_deque')
						# breadth_first_search                finished 10000 runs in 0.20999 seconds
						# breadth_first_search_with_deque     finished 10000 runs in 0.01421 seconds










'''simple docstring'''





def __UpperCAmelCase (			A			:	list[list[int]]						)  -> bool:
			# must be
			UpperCAmelCase_     :   int       =   [list(A						) for row in matrix]
			if matrix and isinstance(A	,   A						):
						if isinstance(matrix[0]	,   A						):
									UpperCAmelCase_     :   Optional[Any]       =   0
									for row in matrix:
												if prev_len == 0:
															UpperCAmelCase_     :   List[str]       =   len(A						)
															UpperCAmelCase_     :   Any       =   True
												else:
															UpperCAmelCase_     :   Tuple       =   prev_len == len(A						)
						else:
									UpperCAmelCase_     :   Any       =   True
			else:
						UpperCAmelCase_     :   Dict       =   False

			return result
def __UpperCAmelCase (			A			:	list[list[int]]						)  -> None:
			if check_matrix(A						) and len(A						) > 0:
						UpperCAmelCase_     :   Dict       =   [list(A						) for row in a]
						UpperCAmelCase_     :   List[Any]       =   len(A						)
						if isinstance(a[0]	,   A						):
									UpperCAmelCase_     :   Any       =   len(a[0]						)
						else:
									for dat in a:
												print(A						)
									return

						# horizotal printing increasing
						for i in range(0	,   A						):
									print(a[0][i]						)
						# vertical printing down
						for i in range(1	,   A						):
									print(a[i][mat_col - 1]						)
						# horizotal printing decreasing
						if mat_row > 1:
									for i in range(mat_col - 2	,   -1	,   -1						):
												print(a[mat_row - 1][i]						)
        # vertical printing up
						for i in range(mat_row - 2	,   0	,   -1						):
									print(a[i][0]						)
						UpperCAmelCase_     :   Union[str, Any]       =   [row[1 : mat_col - 1] for row in a[1 : mat_row - 1]]
						if len(A						) > 0:
									spiral_print_clockwise(A						)
						else:
									return
			else:
						print('''Not a valid matrix'''						)
						return
def __UpperCAmelCase (			A			:	list[list]						)  -> list[int]:
			if matrix:
						return list(matrix.pop(0						)						) + spiral_traversal(list(zip(*A						)						)[::-1]						)
			else:
						return []


# driver code
if __name__ == "__main__":
						import doctest

						doctest.testmod()

						_UpperCamelCase		:		List[Any]								=			[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
						spiral_print_clockwise(a)


