


import json
import os
import random
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import BertTokenizer, BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
			from PIL import Image

			from transformers import FlavaImageProcessor, FlavaProcessor
			from transformers.models.flava.image_processing_flava import (
			    FLAVA_CODEBOOK_MEAN,
			    FLAVA_CODEBOOK_STD,
			    FLAVA_IMAGE_MEAN,
			    FLAVA_IMAGE_STD,
			)

@require_vision
class 			lowerCamelCase_					(    unittest.TestCase    ):





							def   __magic_name__      (							self    ):
								a_     			=   tempfile.mkdtemp()

								# fmt: off
								a_     			=   ["""[UNK]""", """[CLS]""", """[SEP]""", """[PAD]""", """[MASK]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing""", """,""", """low""", """lowest"""]
								# fmt: on
								a_     			=   os.path.join(self.tmpdirname			,       VOCAB_FILES_NAMES["""vocab_file"""]    )

								with open(self.vocab_file			,       """w"""			,       encoding="""utf-8"""    ) as fp:
									fp.write("""""".join([x + """\n""" for x in vocab_tokens]    )    )

								a_     			=   {
								    """image_mean""": FLAVA_IMAGE_MEAN,
								    """image_std""": FLAVA_IMAGE_STD,
								    """do_normalize""": True,
								    """do_resize""": True,
								    """size""": 224,
								    """do_center_crop""": True,
								    """crop_size""": 224,
								    """input_size_patches""": 14,
								    """total_mask_patches""": 75,
								    """mask_group_max_patches""": None,
								    """mask_group_min_patches""": 16,
								    """mask_group_min_aspect_ratio""": 0.3,
								    """mask_group_max_aspect_ratio""": None,
								    """codebook_do_resize""": True,
								    """codebook_size""": 112,
								    """codebook_do_center_crop""": True,
								    """codebook_crop_size""": 112,
								    """codebook_do_map_pixels""": True,
								    """codebook_do_normalize""": True,
								    """codebook_image_mean""": FLAVA_CODEBOOK_MEAN,
								    """codebook_image_std""": FLAVA_CODEBOOK_STD,
								}

								a_     			=   os.path.join(self.tmpdirname			,       _SCREAMING_SNAKE_CASE    )
								with open(self.image_processor_file			,       """w"""			,       encoding="""utf-8"""    ) as fp:
									json.dump(_SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE    )





							def   __magic_name__      (							self			,       **_SCREAMING_SNAKE_CASE    ):
								return BertTokenizer.from_pretrained(self.tmpdirname			,       **_SCREAMING_SNAKE_CASE    )





							def   __magic_name__      (							self			,       **_SCREAMING_SNAKE_CASE    ):
								return BertTokenizerFast.from_pretrained(self.tmpdirname			,       **_SCREAMING_SNAKE_CASE    )





							def   __magic_name__      (							self			,       **_SCREAMING_SNAKE_CASE    ):
								return FlavaImageProcessor.from_pretrained(self.tmpdirname			,       **_SCREAMING_SNAKE_CASE    )





							def   __magic_name__      (							self    ):
								shutil.rmtree(self.tmpdirname    )





							def   __magic_name__      (							self    ):
								a_     			=   [np.random.randint(255			,       size=(3, 30, 400)			,       dtype=np.uinta    )]

								a_     			=   [Image.fromarray(np.moveaxis(_SCREAMING_SNAKE_CASE			,       0			,       -1    )    ) for x in image_inputs]

								return image_inputs





							def   __magic_name__      (							self    ):
								a_     			=   self.get_tokenizer()
								a_     			=   self.get_rust_tokenizer()
								a_     			=   self.get_image_processor()

								a_     			=   FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE			,       image_processor=_SCREAMING_SNAKE_CASE    )
								processor_slow.save_pretrained(self.tmpdirname    )
								a_     			=   FlavaProcessor.from_pretrained(self.tmpdirname			,       use_fast=_SCREAMING_SNAKE_CASE    )

								a_     			=   FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE			,       image_processor=_SCREAMING_SNAKE_CASE    )
								processor_fast.save_pretrained(self.tmpdirname    )
								a_     			=   FlavaProcessor.from_pretrained(self.tmpdirname    )

								self.assertEqual(processor_slow.tokenizer.get_vocab()			,       tokenizer_slow.get_vocab()    )
								self.assertEqual(processor_fast.tokenizer.get_vocab()			,       tokenizer_fast.get_vocab()    )
								self.assertEqual(tokenizer_slow.get_vocab()			,       tokenizer_fast.get_vocab()    )
								self.assertIsInstance(processor_slow.tokenizer			,       _SCREAMING_SNAKE_CASE    )
								self.assertIsInstance(processor_fast.tokenizer			,       _SCREAMING_SNAKE_CASE    )

								self.assertEqual(processor_slow.image_processor.to_json_string()			,       image_processor.to_json_string()    )
								self.assertEqual(processor_fast.image_processor.to_json_string()			,       image_processor.to_json_string()    )
								self.assertIsInstance(processor_slow.image_processor			,       _SCREAMING_SNAKE_CASE    )
								self.assertIsInstance(processor_fast.image_processor			,       _SCREAMING_SNAKE_CASE    )





							def   __magic_name__      (							self    ):
								a_     			=   FlavaProcessor(tokenizer=self.get_tokenizer()			,       image_processor=self.get_image_processor()    )
								processor.save_pretrained(self.tmpdirname    )

								a_     			=   self.get_tokenizer(bos_token="""(BOS)"""			,       eos_token="""(EOS)"""    )
								a_     			=   self.get_image_processor(do_normalize=_SCREAMING_SNAKE_CASE			,       padding_value=1.0    )

								a_     			=   FlavaProcessor.from_pretrained(
								    self.tmpdirname			,       bos_token="""(BOS)"""			,       eos_token="""(EOS)"""			,       do_normalize=_SCREAMING_SNAKE_CASE			,       padding_value=1.0    )

								self.assertEqual(processor.tokenizer.get_vocab()			,       tokenizer_add_kwargs.get_vocab()    )
								self.assertIsInstance(processor.tokenizer			,       _SCREAMING_SNAKE_CASE    )

								self.assertEqual(processor.image_processor.to_json_string()			,       image_processor_add_kwargs.to_json_string()    )
								self.assertIsInstance(processor.image_processor			,       _SCREAMING_SNAKE_CASE    )





							def   __magic_name__      (							self    ):
								a_     			=   self.get_image_processor()
								a_     			=   self.get_tokenizer()

								a_     			=   FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE			,       image_processor=_SCREAMING_SNAKE_CASE    )

								a_     			=   self.prepare_image_inputs()

								a_     			=   image_processor(_SCREAMING_SNAKE_CASE			,       return_tensors="""np"""    )
								a_     			=   processor(images=_SCREAMING_SNAKE_CASE			,       return_tensors="""np"""    )

								for key in input_feat_extract.keys():
									self.assertAlmostEqual(input_feat_extract[key].sum()			,       input_processor[key].sum()			,       delta=1E-2    )

								# With rest of the args
								random.seed(1234    )
								a_     			=   image_processor(
								    _SCREAMING_SNAKE_CASE			,       return_image_mask=_SCREAMING_SNAKE_CASE			,       return_codebook_pixels=_SCREAMING_SNAKE_CASE			,       return_tensors="""np"""    )
								random.seed(1234    )
								a_     			=   processor(
								    images=_SCREAMING_SNAKE_CASE			,       return_image_mask=_SCREAMING_SNAKE_CASE			,       return_codebook_pixels=_SCREAMING_SNAKE_CASE			,       return_tensors="""np"""    )

								for key in input_feat_extract.keys():
									self.assertAlmostEqual(input_feat_extract[key].sum()			,       input_processor[key].sum()			,       delta=1E-2    )





							def   __magic_name__      (							self    ):
								a_     			=   self.get_image_processor()
								a_     			=   self.get_tokenizer()

								a_     			=   FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE			,       image_processor=_SCREAMING_SNAKE_CASE    )

								a_     			=   """lower newer"""

								a_     			=   processor(text=_SCREAMING_SNAKE_CASE    )

								a_     			=   tokenizer(_SCREAMING_SNAKE_CASE    )

								for key in encoded_tok.keys():
									self.assertListEqual(encoded_tok[key]			,       encoded_processor[key]    )





							def   __magic_name__      (							self    ):
								a_     			=   self.get_image_processor()
								a_     			=   self.get_tokenizer()

								a_     			=   FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE			,       image_processor=_SCREAMING_SNAKE_CASE    )

								a_     			=   """lower newer"""
								a_     			=   self.prepare_image_inputs()

								a_     			=   processor(text=_SCREAMING_SNAKE_CASE			,       images=_SCREAMING_SNAKE_CASE    )

								self.assertListEqual(list(inputs.keys()    )			,       ["""input_ids""", """token_type_ids""", """attention_mask""", """pixel_values"""]    )

								# add extra args
								a_     			=   processor(text=_SCREAMING_SNAKE_CASE			,       images=_SCREAMING_SNAKE_CASE			,       return_codebook_pixels=_SCREAMING_SNAKE_CASE			,       return_image_mask=_SCREAMING_SNAKE_CASE    )

								self.assertListEqual(
								    list(inputs.keys()    )			,       [
								        """input_ids""",
								        """token_type_ids""",
								        """attention_mask""",
								        """pixel_values""",
								        """codebook_pixel_values""",
								        """bool_masked_pos""",
								    ]			,       )

								# test if it raises when no input is passed
								with pytest.raises(_SCREAMING_SNAKE_CASE    ):
									processor()





							def   __magic_name__      (							self    ):
								a_     			=   self.get_image_processor()
								a_     			=   self.get_tokenizer()

								a_     			=   FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE			,       image_processor=_SCREAMING_SNAKE_CASE    )

								a_     			=   [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

								a_     			=   processor.batch_decode(_SCREAMING_SNAKE_CASE    )
								a_     			=   tokenizer.batch_decode(_SCREAMING_SNAKE_CASE    )

								self.assertListEqual(_SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE    )





							def   __magic_name__      (							self    ):
								a_     			=   self.get_image_processor()
								a_     			=   self.get_tokenizer()

								a_     			=   FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE			,       image_processor=_SCREAMING_SNAKE_CASE    )

								a_     			=   """lower newer"""
								a_     			=   self.prepare_image_inputs()

								a_     			=   processor(text=_SCREAMING_SNAKE_CASE			,       images=_SCREAMING_SNAKE_CASE    )

								self.assertListEqual(list(inputs.keys()    )			,       processor.model_input_names    )



from collections import deque

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Dict	)     ->	Tuple:



	"""simple docstring"""






	return input(UpperCamelCase	).strip().split(""" """	)

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      int     ,					UpperCamelCase		:      int	)     ->	dict[int, list[int]]:



	"""simple docstring"""






	a_     			=   {}
	for i in range(UpperCamelCase	):
		a_     			=   []

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

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      int     ,					UpperCamelCase		:      int	)     ->	dict[int, list[int]]:



	"""simple docstring"""






	a_     			=   {}
	for i in range(UpperCamelCase	):
		a_     			=   []

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

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      int     ,					UpperCamelCase		:      int	)     ->	dict[int, list[tuple[int, int]]]:



	"""simple docstring"""






	a_     			=   {}
	for i in range(UpperCamelCase	):
		a_     			=   []

	for e in range(UpperCamelCase	):
		a_			, a_			, a_     			=   (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 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Tuple     ,					UpperCamelCase		:      Tuple	)     ->	List[Any]:



	"""simple docstring"""






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

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Tuple     ,					UpperCamelCase		:      int	)     ->	int:



	"""simple docstring"""






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

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      int     ,					UpperCamelCase		:      Any	)     ->	Union[str, Any]:



	"""simple docstring"""






	a_			, a_			, a_     			=   {s: 0}, set(), {s: 0}
	while True:
		if len(UpperCamelCase	) == len(UpperCamelCase	) - 1:
			break
		a_     			=   10_0000
		for i in dist:
			if i not in known and dist[i] < mini:
				a_     			=   dist[i]
				a_     			=   i
		known.add(UpperCamelCase	)
		for v in g[u]:
			if v[0] not in known and dist[u] + v[1] < dist.get(v[0]     ,					10_0000	):
				a_     			=   dist[u] + v[1]
				a_     			=   u
	for i in dist:
		if i != s:
			print(dist[i]	)

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Dict     ,					UpperCamelCase		:      int=None     ,					UpperCamelCase		:      int=None	)     ->	Union[str, Any]:



	"""simple docstring"""






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

def 			__SCREAMING_SNAKE_CASE		(		)     ->	List[Any]:



	"""simple docstring"""






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

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      List[Any]	)     ->	List[str]:



	"""simple docstring"""






	((a_)			, (a_))     			=   a_and_n
	a_     			=   list(UpperCamelCase	)
	a_     			=   [[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]:
					a_     			=   dist[i][k] + dist[k][j]
					a_     			=   k
	print(UpperCamelCase	)

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Dict     ,					UpperCamelCase		:      List[Any]	)     ->	str:



	"""simple docstring"""






	a_			, a_			, a_     			=   {s: 0}, set(), {s: 0}
	while True:
		if len(UpperCamelCase	) == len(UpperCamelCase	) - 1:
			break
		a_     			=   10_0000
		for i in dist:
			if i not in known and dist[i] < mini:
				a_     			=   dist[i]
				a_     			=   i
		known.add(UpperCamelCase	)
		for v in g[u]:
			if v[0] not in known and v[1] < dist.get(v[0]     ,					10_0000	):
				a_     			=   v[1]
				a_     			=   u
	return dist

def 			__SCREAMING_SNAKE_CASE		(		)     ->	int:



	"""simple docstring"""






	a_			, a_     			=   map(UpperCamelCase     ,					input().split(""" """	)	)
	a_     			=   []
	for _ in range(UpperCamelCase	):
		edges.append(map(UpperCamelCase     ,					input().split(""" """	)	)	)
	return edges, n

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      List[str]	)     ->	List[str]:



	"""simple docstring"""






	((a_)			, (a_))     			=   e_and_n
	e.sort(reverse=UpperCamelCase     ,					key=lambda UpperCamelCase	: x[2]	)
	a_     			=   [{i} for i in range(1     ,					n + 1	)]
	while True:
		if len(UpperCamelCase	) == 1:
			break
		print(UpperCamelCase	)
		a_     			=   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 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      str	)     ->	Optional[Any]:



	"""simple docstring"""






	a_     			=   []
	for node in graph:
		if not graph[node]:
			isolated.append(UpperCamelCase	)
	return isolated