'''simple docstring'''




import argparse

from tax import checkpoints

from transformers import FlaxTaForConditionalGeneration, TaConfig




def 				lowerCamelCase      ( UpperCAmelCase__			:   int , UpperCAmelCase__			:   Any , UpperCAmelCase__			:   Tuple					)     -> Optional[int]:
							lowercase_   :     int									=			TaConfig.from_pretrained(UpperCAmelCase__					)
							lowercase_   :     List[Any]									=			FlaxTaForConditionalGeneration(config=UpperCAmelCase__					)
							lowercase_   :     str									=			checkpoints.load_tax_checkpoint(UpperCAmelCase__					)

							lowercase_   :     Dict									=			"""wi_0""" in tax_model["""target"""]["""encoder"""]["""layers_0"""]["""mlp"""]

							# Encoder
							for layer_index in range(config.num_layers					):
														lowercase_   :     Optional[int]									=			F'''layers_{str(UpperCAmelCase__					)}'''

														# Self-Attention
														lowercase_   :     Any									=			tax_model["""target"""]["""encoder"""][layer_name]["""attention"""]["""key"""]["""kernel"""]
														lowercase_   :     Any									=			tax_model["""target"""]["""encoder"""][layer_name]["""attention"""]["""out"""]["""kernel"""]
														lowercase_   :     Any									=			tax_model["""target"""]["""encoder"""][layer_name]["""attention"""]["""query"""]["""kernel"""]
														lowercase_   :     Optional[Any]									=			tax_model["""target"""]["""encoder"""][layer_name]["""attention"""]["""value"""]["""kernel"""]

														# Layer Normalization
														lowercase_   :     Any									=			tax_model["""target"""]["""encoder"""][layer_name]["""pre_attention_layer_norm"""]["""scale"""]

														if split_mlp_wi:
																					lowercase_   :     List[str]									=			tax_model["""target"""]["""encoder"""][layer_name]["""mlp"""]["""wi_0"""]["""kernel"""]
																					lowercase_   :     Optional[int]									=			tax_model["""target"""]["""encoder"""][layer_name]["""mlp"""]["""wi_1"""]["""kernel"""]
														else:
																					lowercase_   :     Optional[int]									=			tax_model["""target"""]["""encoder"""][layer_name]["""mlp"""]["""wi"""]["""kernel"""]

														lowercase_   :     str									=			tax_model["""target"""]["""encoder"""][layer_name]["""mlp"""]["""wo"""]["""kernel"""]

														# Layer Normalization
														lowercase_   :     str									=			tax_model["""target"""]["""encoder"""][layer_name]["""pre_mlp_layer_norm"""]["""scale"""]

														# Assigning
														lowercase_   :     Tuple									=			tax_attention_key
														lowercase_   :     Union[str, Any]									=			tax_attention_out
														lowercase_   :     Optional[Any]									=			tax_attention_query
														lowercase_   :     Any									=			tax_attention_value

														lowercase_   :     Dict									=			tax_attention_layer_norm

														if split_mlp_wi:
																					lowercase_   :     List[Any]									=			tax_mlp_wi_a
																					lowercase_   :     Optional[int]									=			tax_mlp_wi_a
														else:
																					lowercase_   :     str									=			tax_mlp_wi

														lowercase_   :     List[Any]									=			tax_mlp_wo
														lowercase_   :     Optional[Any]									=			tax_mlp_layer_norm

							# Only for layer 0:
							lowercase_   :     int									=			tax_model["""target"""]["""encoder"""]["""relpos_bias"""]["""rel_embedding"""].T
							lowercase_   :     Any									=			tax_encoder_rel_embedding

							# Assigning
							lowercase_   :     Union[str, Any]									=			tax_model["""target"""]["""encoder"""]["""encoder_norm"""]["""scale"""]
							lowercase_   :     int									=			tax_encoder_norm

							# Decoder
							for layer_index in range(config.num_decoder_layers					):
														lowercase_   :     List[str]									=			F'''layers_{str(UpperCAmelCase__					)}'''

														# Self-Attention
														lowercase_   :     int									=			tax_model["""target"""]["""decoder"""][layer_name]["""self_attention"""]["""key"""]["""kernel"""]
														lowercase_   :     List[str]									=			tax_model["""target"""]["""decoder"""][layer_name]["""self_attention"""]["""out"""]["""kernel"""]
														lowercase_   :     Optional[Any]									=			tax_model["""target"""]["""decoder"""][layer_name]["""self_attention"""]["""query"""]["""kernel"""]
														lowercase_   :     Optional[Any]									=			tax_model["""target"""]["""decoder"""][layer_name]["""self_attention"""]["""value"""]["""kernel"""]

														# Layer Normalization
														lowercase_   :     str									=			tax_model["""target"""]["""decoder"""][layer_name]["""pre_self_attention_layer_norm"""][
														    """scale"""
														]

														# Encoder-Decoder-Attention
														lowercase_   :     List[str]									=			tax_model["""target"""]["""decoder"""][layer_name]["""encoder_decoder_attention"""]["""key"""][
														    """kernel"""
														]
														lowercase_   :     Dict									=			tax_model["""target"""]["""decoder"""][layer_name]["""encoder_decoder_attention"""]["""out"""][
														    """kernel"""
														]
														lowercase_   :     Optional[int]									=			tax_model["""target"""]["""decoder"""][layer_name]["""encoder_decoder_attention"""]["""query"""][
														    """kernel"""
														]
														lowercase_   :     List[str]									=			tax_model["""target"""]["""decoder"""][layer_name]["""encoder_decoder_attention"""]["""value"""][
														    """kernel"""
														]

														# Layer Normalization
														lowercase_   :     List[Any]									=			tax_model["""target"""]["""decoder"""][layer_name]["""pre_cross_attention_layer_norm"""]["""scale"""]

														# MLP
														if split_mlp_wi:
																					lowercase_   :     Union[str, Any]									=			tax_model["""target"""]["""decoder"""][layer_name]["""mlp"""]["""wi_0"""]["""kernel"""]
																					lowercase_   :     Optional[Any]									=			tax_model["""target"""]["""decoder"""][layer_name]["""mlp"""]["""wi_1"""]["""kernel"""]
														else:
																					lowercase_   :     Dict									=			tax_model["""target"""]["""decoder"""][layer_name]["""mlp"""]["""wi"""]["""kernel"""]

														lowercase_   :     List[str]									=			tax_model["""target"""]["""decoder"""][layer_name]["""mlp"""]["""wo"""]["""kernel"""]

														# Layer Normalization
														lowercase_   :     Optional[int]									=			tax_model["""target"""]["""decoder"""][layer_name]["""pre_mlp_layer_norm"""]["""scale"""]

														# Assigning
														lowercase_   :     Tuple									=			tax_attention_key
														lowercase_   :     List[Any]									=			tax_attention_out
														lowercase_   :     Optional[int]									=			tax_attention_query
														lowercase_   :     Optional[Any]									=			tax_attention_value

														lowercase_   :     Optional[int]									=			tax_pre_attention_layer_norm

														lowercase_   :     Union[str, Any]									=			tax_enc_dec_attention_key
														lowercase_   :     List[Any]									=			tax_enc_dec_attention_out
														lowercase_   :     int									=			tax_enc_dec_attention_query
														lowercase_   :     Optional[int]									=			tax_enc_dec_attention_value

														lowercase_   :     int									=			tax_cross_layer_norm

														if split_mlp_wi:
																					lowercase_   :     int									=			tax_mlp_wi_a
																					lowercase_   :     str									=			tax_mlp_wi_a
														else:
																					lowercase_   :     Any									=			tax_mlp_wi

														lowercase_   :     List[str]									=			tax_mlp_wo

														lowercase_   :     Optional[int]									=			txa_mlp_layer_norm

							# Decoder Normalization
							lowercase_   :     Any									=			tax_model["""target"""]["""decoder"""]["""decoder_norm"""]["""scale"""]
							lowercase_   :     Dict									=			txa_decoder_norm

							# Only for layer 0:
							lowercase_   :     str									=			tax_model["""target"""]["""decoder"""]["""relpos_bias"""]["""rel_embedding"""].T
							lowercase_   :     Any									=			tax_decoder_rel_embedding

							# Token Embeddings
							lowercase_   :     List[str]									=			tax_model["""target"""]["""token_embedder"""]["""embedding"""]
							lowercase_   :     List[str]									=			txa_token_embeddings

							# LM Head (only in v1.1 checkpoints)
							if "logits_dense" in tax_model["target"]["decoder"]:
														lowercase_   :     int									=			tax_model["""target"""]["""decoder"""]["""logits_dense"""]["""kernel"""]

							flax_model.save_pretrained(UpperCAmelCase__					)
							print("""T5X Model was sucessfully converted!"""					)


if __name__ == "__main__":
						_lowercase		:					Optional[int]													=		argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    "--t5x_checkpoint_path", default=None, type=str, required=True, help="Path the TX5 checkpoint."
						)
						parser.add_argument("--config_name", default=None, type=str, required=True, help="Config name of T5 model.")
						parser.add_argument(
						    "--flax_dump_folder_path", default=None, type=str, required=True, help="Path to the output FLAX model."
						)
						_lowercase		:					Union[str, Any]													=		parser.parse_args()
						convert_tax_checkpoint_to_flax(args.tax_checkpoint_path, args.config_name, args.flax_dump_folder_path)






'''simple docstring'''




from __future__ import annotations




def 				lowerCamelCase      ( UpperCAmelCase__			:   str					)     -> Any:
							global graph, reversed_graph, scc, component, visit, stack
							if visit[u]:
														return
							lowercase_   :     int									=			True
							for v in graph[u]:
														dfs(UpperCAmelCase__					)
							stack.append(UpperCAmelCase__					)




def 				lowerCamelCase      ( UpperCAmelCase__			:   int					)     -> str:
							global graph, reversed_graph, scc, component, visit, stack
							if visit[u]:
														return
							lowercase_   :     Tuple									=			True
							component.append(UpperCAmelCase__					)
							for v in reversed_graph[u]:
														dfsa(UpperCAmelCase__					)




def 				lowerCamelCase      ( )     -> int:
							global graph, reversed_graph, scc, component, visit, stack
							for i in range(UpperCAmelCase__					):
														dfs(UpperCAmelCase__					)
							lowercase_   :     Optional[int]									=			[False] * n
							for i in stack[::-1]:
														if visit[i]:
																					continue
														lowercase_   :     Union[str, Any]									=			[]
														dfsa(UpperCAmelCase__					)
														scc.append(UpperCAmelCase__					)
							return scc


if __name__ == "__main__":
						# n - no of nodes, m - no of edges
						_lowercase							,			_lowercase		:					Optional[Any]													=		list(map(int, input().strip().split()))

						_lowercase		:					list[list[int]]													=		[[] for _ in range(n)]  # graph
						_lowercase		:					list[list[int]]													=		[[] for i in range(n)]  # reversed graph
						# input graph data (edges)
						for _ in range(m):
												_lowercase							,			_lowercase		:					Tuple													=		list(map(int, input().strip().split()))
												graph[u].append(v)
												reversed_graph[v].append(u)

						_lowercase		:					list[int]													=		[]
						_lowercase		:					list[bool]													=		[False] * n
						_lowercase		:					list[int]													=		[]
						_lowercase		:					list[int]													=		[]
						print(kosaraju())





