


from collections import deque





def 			__lowercase	(						_UpperCamelCase     )    ->Optional[int]:







      """simple docstring"""

      return input(_UpperCamelCase     ).strip().split(''' '''     )





def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->dict[int, list[int]]:







      """simple docstring"""

      lowercase			:   dict[int, list[int]]					   =		{}
      for i in range(_UpperCamelCase     ):
            lowercase			:   Optional[int]					   =		[]

      for e in range(_UpperCamelCase     ):
            lowercase			:   List[str]					   =		(int(_UpperCamelCase     ) for i in _input(f"""Edge {e + 1}: <node1> <node2> """     ))
            graph[x].append(_UpperCamelCase     )
      return graph





def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->dict[int, list[int]]:







      """simple docstring"""

      lowercase			:   dict[int, list[int]]					   =		{}
      for i in range(_UpperCamelCase     ):
            lowercase			:   int					   =		[]

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





def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->dict[int, list[tuple[int, int]]]:







      """simple docstring"""

      lowercase			:   dict[int, list[tuple[int, int]]]					   =		{}
      for i in range(_UpperCamelCase     ):
            lowercase			:   Dict					   =		[]

      for e in range(_UpperCamelCase     ):
            lowercase			:   List[Any]					   =		(int(_UpperCamelCase     ) 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__":
  __a				,      __a   				=      (int(i) for i in _input('''Number of nodes and edges: '''))

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

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





def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->Optional[int]:







      """simple docstring"""

      lowercase			:   Tuple					   =		{s}, [s]
      print(_UpperCamelCase     )
      while _s:
            lowercase			:   str					   =		0
            for i in g[_s[-1]]:
                  if i not in vis:
                        _s.append(_UpperCamelCase     )
                        vis.add(_UpperCamelCase     )
                        lowercase			:   Tuple					   =		1
                        print(_UpperCamelCase     )
                        break
            if not flag:
                  _s.pop()





def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->Any:







      """simple docstring"""

      lowercase			:   Any					   =		{s}, deque([s]     )
      print(_UpperCamelCase     )
      while q:
            lowercase			:   Optional[Any]					   =		q.popleft()
            for v in g[u]:
                  if v not in vis:
                        vis.add(_UpperCamelCase     )
                        q.append(_UpperCamelCase     )
                        print(_UpperCamelCase     )





def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->Optional[Any]:







      """simple docstring"""

      lowercase			:   Tuple					   =		{s: 0}, set(), {s: 0}
      while True:
            if len(_UpperCamelCase     ) == len(_UpperCamelCase     ) - 1:
                  break
            lowercase			:   Any					   =		100000
            for i in dist:
                  if i not in known and dist[i] < mini:
                        lowercase			:   int					   =		dist[i]
                        lowercase			:   int					   =		i
            known.add(_UpperCamelCase     )
            for v in g[u]:
                  if v[0] not in known and dist[u] + v[1] < dist.get(v[0],    100000     ):
                        lowercase			:   int					   =		dist[u] + v[1]
                        lowercase			:   Union[str, Any]					   =		u
      for i in dist:
            if i != s:
                  print(dist[i]     )





def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase=None,    _UpperCamelCase=None     )    ->Union[str, Any]:







      """simple docstring"""

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





def 			__lowercase	(						)    ->int:







      """simple docstring"""

      lowercase			:   int					   =		input().strip()
      lowercase			:   int					   =		[]
      for _ in range(_UpperCamelCase     ):
            a.append(map(_UpperCamelCase,    input().strip().split()     )     )
      return a, n





def 			__lowercase	(						_UpperCamelCase     )    ->Union[str, Any]:







      """simple docstring"""

      (lowercase)			:   Any					   =		a_and_n
      lowercase			:   Union[str, Any]					   =		list(_UpperCamelCase     )
      lowercase			:   List[str]					   =		[[0] * n for i in range(_UpperCamelCase     )]
      for k in range(_UpperCamelCase     ):
            for i in range(_UpperCamelCase     ):
                  for j in range(_UpperCamelCase     ):
                        if dist[i][j] > dist[i][k] + dist[k][j]:
                              lowercase			:   Any					   =		dist[i][k] + dist[k][j]
                              lowercase			:   List[str]					   =		k
      print(_UpperCamelCase     )





def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->Union[str, Any]:







      """simple docstring"""

      lowercase			:   List[str]					   =		{s: 0}, set(), {s: 0}
      while True:
            if len(_UpperCamelCase     ) == len(_UpperCamelCase     ) - 1:
                  break
            lowercase			:   str					   =		100000
            for i in dist:
                  if i not in known and dist[i] < mini:
                        lowercase			:   int					   =		dist[i]
                        lowercase			:   int					   =		i
            known.add(_UpperCamelCase     )
            for v in g[u]:
                  if v[0] not in known and v[1] < dist.get(v[0],    100000     ):
                        lowercase			:   str					   =		v[1]
                        lowercase			:   Any					   =		u
      return dist





def 			__lowercase	(						)    ->Tuple:







      """simple docstring"""

      lowercase			:   Optional[int]					   =		map(_UpperCamelCase,    input().split(''' '''     )     )
      lowercase			:   Optional[Any]					   =		[]
      for _ in range(_UpperCamelCase     ):
            edges.append(map(_UpperCamelCase,    input().split(''' '''     )     )     )
      return edges, n





def 			__lowercase	(						_UpperCamelCase     )    ->Optional[Any]:







      """simple docstring"""

      (lowercase)			:   List[Any]					   =		e_and_n
      e.sort(reverse=_UpperCamelCase,    key=lambda _UpperCamelCase     : x[2]     )
      lowercase			:   Any					   =		[{i} for i in range(1,    n + 1     )]
      while True:
            if len(_UpperCamelCase     ) == 1:
                  break
            print(_UpperCamelCase     )
            lowercase			:   Dict					   =		e.pop()
            for i in range(len(_UpperCamelCase     )     ):
                  if x[0] in s[i]:
                        break
            for j in range(len(_UpperCamelCase     )     ):
                  if x[1] in s[j]:
                        if i == j:
                              break
                        s[j].update(s[i]     )
                        s.pop(_UpperCamelCase     )
                        break





def 			__lowercase	(						_UpperCamelCase     )    ->Union[str, Any]:







      """simple docstring"""

      lowercase			:   Optional[Any]					   =		[]
      for node in graph:
            if not graph[node]:
                  isolated.append(_UpperCamelCase     )
      return isolated





import argparse
import logging

import numpy as np
import torch

from transformers import AutoModelForCausalLM, AutoTokenizer


logging.basicConfig(
    format='''%(asctime)s - %(levelname)s - %(name)s - %(message)s''',
    datefmt='''%m/%d/%Y %H:%M:%S''',
    level=logging.INFO,
)
__a   				=      logging.getLogger(__name__)




def 			__lowercase	(						_UpperCamelCase     )    ->Any:







      """simple docstring"""

      np.random.seed(args.seed     )
      torch.manual_seed(args.seed     )
      if args.n_gpu > 0:
            torch.cuda.manual_seed_all(args.seed     )




def 			__lowercase	(						)    ->List[str]:







      """simple docstring"""

      lowercase			:   List[str]					   =		argparse.ArgumentParser()
      parser.add_argument(
          '''--model_name_or_path''',    default=_UpperCamelCase,    type=_UpperCamelCase,    required=_UpperCamelCase,    )
      parser.add_argument('''--prompt''',    type=_UpperCamelCase,    default=''''''     )
      parser.add_argument('''--length''',    type=_UpperCamelCase,    default=20     )
      parser.add_argument('''--stop_token''',    type=_UpperCamelCase,    default=_UpperCamelCase,    help='''Token at which text generation is stopped'''     )
      parser.add_argument(
          '''--temperature''',    type=_UpperCamelCase,    default=1.0,    help='''temperature of 1.0 has no effect, lower tend toward greedy sampling''',    )
      parser.add_argument(
          '''--repetition_penalty''',    type=_UpperCamelCase,    default=1.0,    help='''primarily useful for CTRL model; in that case, use 1.2'''     )
      parser.add_argument('''--k''',    type=_UpperCamelCase,    default=0     )
      parser.add_argument('''--penalty_alpha''',    type=_UpperCamelCase,    default=0.0     )
      parser.add_argument('''--p''',    type=_UpperCamelCase,    default=0.9     )

      parser.add_argument('''--prefix''',    type=_UpperCamelCase,    default='''''',    help='''Text added prior to input.'''     )
      parser.add_argument('''--padding_text''',    type=_UpperCamelCase,    default='''''',    help='''Deprecated, the use of `--prefix` is preferred.'''     )
      parser.add_argument('''--xlm_language''',    type=_UpperCamelCase,    default='''''',    help='''Optional language when used with the XLM model.'''     )

      parser.add_argument('''--seed''',    type=_UpperCamelCase,    default=42,    help='''random seed for initialization'''     )
      parser.add_argument('''--no_cuda''',    action='''store_true''',    help='''Avoid using CUDA when available'''     )
      parser.add_argument(
          '''--fp16''',    action='''store_true''',    help='''Whether to use 16-bit (mixed) precision (through NVIDIA apex) instead of 32-bit''',    )
      lowercase			:   Any					   =		parser.parse_args()

      lowercase			:   int					   =		torch.device('''cuda''' if torch.cuda.is_available() and not args.no_cuda else '''cpu'''     )
      lowercase			:   List[str]					   =		0 if args.no_cuda else torch.cuda.device_count()

      logger.warning(f"""device: {args.device}, n_gpu: {args.n_gpu}, 16-bits training: {args.fpaa}"""     )

      set_seed(_UpperCamelCase     )

      # Initialize the model and tokenizer
      lowercase			:   Optional[Any]					   =		AutoTokenizer.from_pretrained(args.model_name_or_path     )
      lowercase			:   List[Any]					   =		AutoModelForCausalLM.from_pretrained(args.model_name_or_path     )

      # tokenizer = GPT2Tokenizer.from_pretrained(args.model_name_or_path)
      # model = OPTForCausalLM.from_pretrained(args.model_name_or_path)
      model.to(args.device     )

      if args.fpaa:
            model.half()

      logger.info(_UpperCamelCase     )
      lowercase			:   Union[str, Any]					   =		args.prompt if args.prompt else input('''Model prompt >>> '''     )

      lowercase			:   List[Any]					   =		tokenizer(_UpperCamelCase,    return_tensors='''pt''',    add_special_tokens=_UpperCamelCase     )
      lowercase			:   Union[str, Any]					   =		{key: value.to(args.device     ) for key, value in inputs.items()}

      lowercase			:   Optional[int]					   =		model.generate(
          **_UpperCamelCase,    max_length=args.length + len(inputs['''input_ids'''][0]     ),    penalty_alpha=args.penalty_alpha,    top_k=args.k,    )

      lowercase			:   Union[str, Any]					   =		[]
      for generated_sequence_idx, generated_sequence in enumerate(_UpperCamelCase     ):
            print(f"""=== GENERATED SEQUENCE {generated_sequence_idx + 1} ==="""     )
            lowercase			:   Optional[Any]					   =		generated_sequence.tolist()

            # Decode text
            lowercase			:   int					   =		tokenizer.decode(_UpperCamelCase,    clean_up_tokenization_spaces=_UpperCamelCase,    add_special_tokens=_UpperCamelCase     )

            # Remove all text after the stop token
            lowercase			:   Optional[int]					   =		text[: text.find(args.stop_token     ) if args.stop_token else None]

            # Add the prompt at the beginning of the sequence. Remove the excess text that was used for pre-processing
            lowercase			:   Optional[Any]					   =		(
                prompt_text + text[len(tokenizer.decode(inputs['''input_ids'''][0],    clean_up_tokenization_spaces=_UpperCamelCase     )     ) :]
            )

            generated_sequences.append(_UpperCamelCase     )
            print(_UpperCamelCase     )

      return generated_sequences


if __name__ == "__main__":
  main()

