





"""simple docstring"""




from collections import deque





def 	a_    (							_lowercase       ):
						_UpperCamelCase      : Optional[int]         =   len(_lowercase       )
						_UpperCamelCase      : Optional[int]         =   deque()
						_UpperCamelCase      : Dict         =   [False for _ in range(_lowercase       )]
						_UpperCamelCase      : List[str]         =   [-1 for _ in range(_lowercase       )]
						_UpperCamelCase      : str         =   index_of[:]

						def strong_connect(_lowercase	,						_lowercase	,						_lowercase       ):
												_UpperCamelCase      : Union[str, Any]         =   index  # the number when this node is seen
												_UpperCamelCase      : List[Any]         =   index  # lowest rank node reachable from here
												index += 1
												stack.append(_lowercase       )
												_UpperCamelCase      : Dict         =   True

												for w in g[v]:
																		if index_of[w] == -1:
																								_UpperCamelCase      : int         =   strong_connect(_lowercase	,						_lowercase	,						_lowercase       )
																								_UpperCamelCase      : Union[str, Any]         =   (
																								    lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
																								)
																		elif on_stack[w]:
																								_UpperCamelCase      : Tuple         =   (
																								    lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
																								)

												if lowlink_of[v] == index_of[v]:
																		_UpperCamelCase      : int         =   []
																		_UpperCamelCase      : Dict         =   stack.pop()
																		_UpperCamelCase      : Any         =   False
																		component.append(_lowercase       )
																		while w != v:
																								_UpperCamelCase      : Union[str, Any]         =   stack.pop()
																								_UpperCamelCase      : int         =   False
																								component.append(_lowercase       )
																		components.append(_lowercase       )
												return index

						_UpperCamelCase      : Tuple         =   []
						for v in range(_lowercase       ):
												if index_of[v] == -1:
																		strong_connect(_lowercase	,						0	,						_lowercase       )

						return components





def 	a_    (							_lowercase	,						_lowercase       ):
						_UpperCamelCase      : Optional[Any]         =   [[] for _ in range(_lowercase       )]
						for u, v in edges:
												g[u].append(_lowercase       )
						return g


if __name__ == "__main__":
						# Test
						UpperCamelCase_									=7
						UpperCamelCase_									=[0, 0, 1, 2, 3, 3, 4, 4, 6]
						UpperCamelCase_									=[1, 3, 2, 0, 1, 4, 5, 6, 5]
						UpperCamelCase_									=[(u, v) for u, v in zip(source, target)]
						UpperCamelCase_									=create_graph(n_vertices, edges)

						assert [[5], [6], [4], [3, 2, 1, 0]] == tarjan(g)










"""simple docstring"""




from functools import lru_cache





@lru_cache
def 	a_    (							_lowercase       ):
						if num < 0:
												raise ValueError('''Number should not be negative.'''       )

						return 1 if num in (0, 1) else num * factorial(num - 1       )


if __name__ == "__main__":
						import doctest

						doctest.testmod()



