



from collections import deque





def 						__lowerCamelCase       (      __magic_name__	:  Any						):
							return input(__magic_name__						).strip().split(" "						)





def 						__lowerCamelCase       (      __magic_name__	:  int     , __magic_name__	:  int						):
							a__:       dict[int, list[int]]											={}
							for i in range(__magic_name__						):
														a__:       Dict											=[]

							for e in range(__magic_name__						):
														a__:       Any											=(int(__magic_name__						) for i in _input(F"Edge {e + 1}: <node1> <node2> "						))
														graph[x].append(__magic_name__						)
							return graph





def 						__lowerCamelCase       (      __magic_name__	:  int     , __magic_name__	:  int						):
							a__:       dict[int, list[int]]											={}
							for i in range(__magic_name__						):
														a__:       Union[str, Any]											=[]

							for e in range(__magic_name__						):
														a__:       int											=(int(__magic_name__						) for i in _input(F"Edge {e + 1}: <node1> <node2> "						))
														graph[x].append(__magic_name__						)
														graph[y].append(__magic_name__						)
							return graph





def 						__lowerCamelCase       (      __magic_name__	:  int     , __magic_name__	:  int						):
							a__:       dict[int, list[tuple[int, int]]]											={}
							for i in range(__magic_name__						):
														a__:       Dict											=[]

							for e in range(__magic_name__						):
														a__:       str											=(int(__magic_name__						) for i in _input(F"Edge {e + 1}: <node1> <node2> <weight> "						))
														graph[x].append((y, w)						)
														graph[y].append((x, w)						)
							return graph


if __name__ == "__main__":
		__UpperCAmelCase  ,							__UpperCAmelCase						  =     (int(i) for i in _input('''Number of nodes and edges: '''))

		__UpperCAmelCase						  =     int(
		    _input(
		        '''Press 1 or 2 or 3 \n'''
		        '''1. Unweighted directed \n'''
		        '''2. Unweighted undirected \n'''
		        '''3. Weighted undirected \n'''
		    )[0]
		)

		__UpperCAmelCase						  =     {
		    1: initialize_unweighted_directed_graph,
		    2: initialize_unweighted_undirected_graph,
		    3: initialize_weighted_undirected_graph,
		}[graph_choice](n, m)





def 						__lowerCamelCase       (      __magic_name__	:  List[Any]     , __magic_name__	:  int						):
							a__:       Optional[Any]											={s}, [s]
							print(__magic_name__						)
							while _s:
														a__:       str											=0
														for i in g[_s[-1]]:
																					if i not in vis:
																												_s.append(__magic_name__						)
																												vis.add(__magic_name__						)
																												a__:       Union[str, Any]											=1
																												print(__magic_name__						)
																												break
														if not flag:
																					_s.pop()





def 						__lowerCamelCase       (      __magic_name__	:  Tuple     , __magic_name__	:  Union[str, Any]						):
							a__:       Any											={s}, deque([s]						)
							print(__magic_name__						)
							while q:
														a__:       str											=q.popleft()
														for v in g[u]:
																					if v not in vis:
																												vis.add(__magic_name__						)
																												q.append(__magic_name__						)
																												print(__magic_name__						)





def 						__lowerCamelCase       (      __magic_name__	:  Optional[int]     , __magic_name__	:  str						):
							a__:       List[str]											={s: 0}, set(), {s: 0}
							while True:
														if len(__magic_name__						) == len(__magic_name__						) - 1:
																					break
														a__:       str											=100_000
														for i in dist:
																					if i not in known and dist[i] < mini:
																												a__:       int											=dist[i]
																												a__:       str											=i
														known.add(__magic_name__						)
														for v in g[u]:
																					if v[0] not in known and dist[u] + v[1] < dist.get(v[0]     , 100_000						):
																												a__:       Dict											=dist[u] + v[1]
																												a__:       List[str]											=u
							for i in dist:
														if i != s:
																					print(dist[i]						)





def 						__lowerCamelCase       (      __magic_name__	:  Union[str, Any]     , __magic_name__	:  Optional[int]=None     , __magic_name__	:  List[str]=None						):
							if q is None:
														a__:       str											=[1]
							if ind is None:
														a__:       int											=[0] * (len(__magic_name__						) + 1)  # SInce oth Index is ignored
														for u in g:
																					for v in g[u]:
																												ind[v] += 1
														a__:       Optional[int]											=deque()
														for i in g:
																					if ind[i] == 0:
																												q.append(__magic_name__						)
							if len(__magic_name__						) == 0:
														return
							a__:       Any											=q.popleft()
							print(__magic_name__						)
							for w in g[v]:
														ind[w] -= 1
														if ind[w] == 0:
																					q.append(__magic_name__						)
							topo(__magic_name__     , __magic_name__     , __magic_name__						)





def 						__lowerCamelCase       (      ):
							a__:       int											=input().strip()
							a__:       Optional[int]											=[]
							for _ in range(__magic_name__						):
														a.append(map(__magic_name__     , input().strip().split()						)						)
							return a, n





def 						__lowerCamelCase       (      __magic_name__	:  List[str]						):
							(a__):       List[Any]											=a_and_n
							a__:       Union[str, Any]											=list(__magic_name__						)
							a__:       Any											=[[0] * n for i in range(__magic_name__						)]
							for k in range(__magic_name__						):
														for i in range(__magic_name__						):
																					for j in range(__magic_name__						):
																												if dist[i][j] > dist[i][k] + dist[k][j]:
																																			a__:       List[str]											=dist[i][k] + dist[k][j]
																																			a__:       Tuple											=k
							print(__magic_name__						)





def 						__lowerCamelCase       (      __magic_name__	:  Tuple     , __magic_name__	:  Any						):
							a__:       Union[str, Any]											={s: 0}, set(), {s: 0}
							while True:
														if len(__magic_name__						) == len(__magic_name__						) - 1:
																					break
														a__:       Optional[int]											=100_000
														for i in dist:
																					if i not in known and dist[i] < mini:
																												a__:       Dict											=dist[i]
																												a__:       int											=i
														known.add(__magic_name__						)
														for v in g[u]:
																					if v[0] not in known and v[1] < dist.get(v[0]     , 100_000						):
																												a__:       Tuple											=v[1]
																												a__:       Dict											=u
							return dist





def 						__lowerCamelCase       (      ):
							a__:       List[str]											=map(__magic_name__     , input().split(" "						)						)
							a__:       str											=[]
							for _ in range(__magic_name__						):
														edges.append(map(__magic_name__     , input().split(" "						)						)						)
							return edges, n





def 						__lowerCamelCase       (      __magic_name__	:  Optional[int]						):
							# Sort edges on the basis of distance
							(a__):       List[str]											=e_and_n
							e.sort(reverse=__magic_name__     , key=lambda __magic_name__						: x[2]						)
							a__:       Tuple											=[{i} for i in range(1     , n + 1						)]
							while True:
														if len(__magic_name__						) == 1:
																					break
														print(__magic_name__						)
														a__:       int											=e.pop()
														for i in range(len(__magic_name__						)						):
																					if x[0] in s[i]:
																												break
														for j in range(len(__magic_name__						)						):
																					if x[1] in s[j]:
																												if i == j:
																																			break
																												s[j].update(s[i]						)
																												s.pop(__magic_name__						)
																												break







def 						__lowerCamelCase       (      __magic_name__	:  Any						):
							a__:       Union[str, Any]											=[]
							for node in graph:
														if not graph[node]:
																					isolated.append(__magic_name__						)
							return isolated










# This test is meant to be run in on an instance with TPUs like this:
#
#   python examples/pytorch/xla_spawn.py --num_cores=8 tests/test_trainer_tpu.py
#
# Replace 8 with the number of TPU cores you have.
#

import sys
from typing import Dict

from transformers import EvalPrediction, HfArgumentParser, TrainingArguments, is_torch_available
from transformers.utils import logging


__UpperCAmelCase						  =     logging.get_logger(__name__)


if is_torch_available():
		import torch
		from torch import nn
		from torch.utils.data import Dataset

		from transformers import Trainer


		class 	lowerCamelCase__ (		_a   ):


								def __init__( self						:  Any      ,       _a						:  int = 1_0_1			):
															a__:       Dict											=length


								def __len__( self						:  Optional[Any]			):
															return self.length







								def __getitem__( self						:  Dict      ,       _a						:  int			):
															return i


		class 	lowerCamelCase__ :


								def __call__( self						:  Any      ,       _a						:  List[str]			):
															return {"input_ids": torch.tensor(_a			), "labels": torch.tensor(_a			)}


		class 	lowerCamelCase__ (		nn.Module   ):


								def __init__( self						:  Tuple			):
															super().__init__()
															# Add some (unused) params otherwise DDP will complain.
															a__:       int											=nn.Linear(1_2_0      ,       8_0			)







								def   _lowerCamelCase			( self						:  str      ,       _a						:  List[Any]      ,       _a						:  List[str]=None			):
															if labels is not None:
																						return torch.tensor(0.0      ,       device=input_ids.device			), input_ids
															else:
																						return input_ids





def 						__lowerCamelCase       (      ):
							a__:       List[str]											=HfArgumentParser((TrainingArguments,)						)
							sys.argv += ["--output_dir", "./examples"]
							a__:       int											=parser.parse_args_into_dataclasses()[0]

							logger.warning(
							    F"Process rank: {training_args.local_rank}, device: {training_args.device}, "
							    F"tpu_num_cores: {training_args.tpu_num_cores}"     , )

							# Essentially, what we want to verify in the distributed case is
							# that we get all samples back, in the right order.
							# (this is crucial for prediction for instance)
							for dataset_length in [1_001, 256, 15]:
														a__:       Optional[Any]											=DummyDataset(__magic_name__						)

														def compute_metrics(__magic_name__	:  EvalPrediction						) -> Dict:
																					a__:       List[str]											=list(range(len(__magic_name__						)						)						)
																					a__:       Union[str, Any]											=p.predictions.tolist() == sequential and p.label_ids.tolist() == sequential
																					return {"success": success}

														a__:       Union[str, Any]											=Trainer(
														    model=DummyModel()     , args=__magic_name__     , data_collator=DummyDataCollator()     , eval_dataset=__magic_name__     , compute_metrics=__magic_name__     , )
														a__:       str											=trainer.evaluate()
														logger.info(__magic_name__						)
														if metrics["eval_success"] is not True:
																					logger.error(__magic_name__						)
																					exit(1						)

														a__:       List[str]											=trainer.predict(__magic_name__						)
														logger.info(p.metrics						)
														if p.metrics["test_success"] is not True:
																					logger.error(p.metrics						)
																					exit(1						)

														a__:       Tuple											=2

														a__:       Optional[int]											=trainer.evaluate()
														logger.info(__magic_name__						)
														if metrics["eval_success"] is not True:
																					logger.error(__magic_name__						)
																					exit(1						)

														a__:       List[str]											=trainer.predict(__magic_name__						)
														logger.info(p.metrics						)
														if p.metrics["test_success"] is not True:
																					logger.error(p.metrics						)
																					exit(1						)

														a__:       List[str]											=None

							logger.info("🔥 All distributed tests successful"						)





def 						__lowerCamelCase       (      __magic_name__	:  Optional[Any]						):
							# For xla_spawn (TPUs)
							main()


if __name__ == "__main__":
		main()





