






"""simple docstring"""





class       __A		:  # Public class to implement a graph

					def __init__(			self  :      int     ,		__snake_case  :      int     ,		__snake_case  :      int     ,		__snake_case  :      list[list[bool]]					)			->							None:
											__magic_name__:	Tuple							=       row
											__magic_name__:	Any							=       col
											__magic_name__:	Union[str, Any]							=       graph

					def   lowerCamelCase__   (			self  :      Tuple     ,		__snake_case  :      int     ,		__snake_case  :      int     ,		__snake_case  :      list[list[bool]]					)			->							bool:
											return (
											    0 <= i < self.ROW
											    and 0 <= j < self.COL
											    and not visited[i][j]
											    and self.graph[i][j]
											)

					def   lowerCamelCase__   (			self  :      str     ,		__snake_case  :      int     ,		__snake_case  :      int     ,		__snake_case  :      list[list[bool]]					)			->							None:
											# Checking all 8 elements surrounding nth element
											__magic_name__:	int							=       [-1, -1, -1, 0, 0, 1, 1, 1]  # Coordinate order
											__magic_name__:	Tuple							=       [-1, 0, 1, -1, 1, -1, 0, 1]
											__magic_name__:	Optional[int]							=       True  # Make those cells visited
											for k in range(8					):
																	if self.is_safe(i + row_nbr[k]     ,		j + col_nbr[k]     ,		__snake_case					):
																							self.diffs(i + row_nbr[k]     ,		j + col_nbr[k]     ,		__snake_case					)






					def   lowerCamelCase__   (			self  :      str					)			->							int:  # And finally, count all islands.
											__magic_name__:	List[Any]							=       [[False for j in range(self.COL					)] for i in range(self.ROW					)]
											__magic_name__:	Any							=       0
											for i in range(self.ROW					):
																	for j in range(self.COL					):
																							if visited[i][j] is False and self.graph[i][j] == 1:
																													self.diffs(__snake_case     ,		__snake_case     ,		__snake_case					)
																													count += 1
											return count











"""simple docstring"""





def   a    (     __UpperCAmelCase      :    List[Any]  )    ->							str:
						__magic_name__:	Optional[int]							=       [0] * len(__UpperCAmelCase  )
						__magic_name__:	str							=       []
						__magic_name__:	Any							=       []
						__magic_name__:	Union[str, Any]							=       0

						for values in graph.values():
												for i in values:
																		indegree[i] += 1

						for i in range(len(__UpperCAmelCase  )  ):
												if indegree[i] == 0:
																		queue.append(__UpperCAmelCase  )

						while queue:
												__magic_name__:	Optional[Any]							=       queue.pop(0  )
												cnt += 1
												topo.append(__UpperCAmelCase  )
												for x in graph[vertex]:
																		indegree[x] -= 1
																		if indegree[x] == 0:
																								queue.append(__UpperCAmelCase  )

						if cnt != len(__UpperCAmelCase  ):
												print("""Cycle exists"""  )
						else:
												print(__UpperCAmelCase  )


# Adjacency List of Graph
__lowerCamelCase							=  {0: [1, 2], 1: [3], 2: [3], 3: [4, 5], 4: [], 5: []}

topological_sort(graph)



