



UpperCAmelCase							=       float("""inf""")

class 			__snake_case   :







							'''simple docstring'''






							def __init__(				self	,	a_		):
											a__					   =		[0] * n
											a__					   =		[0] * n
											a__					   =		[0] * n
											a__					   =		[[] for _ in range(a_		)]


							def _a   (				self	,	a_	,	a_	,	a_	,	a_=0		):
											self.adj[a].append([b, len(self.adj[b]		), c, 0]		)
											self.adj[b].append([a, len(self.adj[a]		) - 1, rcap, 0]		)


							def _a   (				self	,	a_	,	a_	,	a_		):




											if vertex == sink or not flow:
															return flow

											for i in range(self.ptr[vertex]	,	len(self.adj[vertex]		)		):
															a__					   =		self.adj[vertex][i]
															if self.lvl[e[0]] == self.lvl[vertex] + 1:
																			a__					   =		self.depth_first_search(e[0]	,	a_	,	min(a_	,	e[2] - e[3]		)		)
																			if p:
																							self.adj[vertex][i][3] += p
																							self.adj[e[0]][e[1]][3] -= p
																							return p
															a__					   =		self.ptr[vertex] + 1
											return 0







							def _a   (				self	,	a_	,	a_		):
											a__					   =		0, source
											for l in range(31		):  # noqa: E741  l = 30 maybe faster for random data
															while True:
																			a__					   =		[0] * len(self.q		), [0] * len(self.q		)
																			a__					   =		0, 1, 1
																			while qi < qe and not self.lvl[sink]:
																							a__					   =		self.q[qi]
																							qi += 1
																							for e in self.adj[v]:
																											if not self.lvl[e[0]] and (e[2] - e[3]) >> (30 - l):
																															a__					   =		e[0]
																															qe += 1
																															a__					   =		self.lvl[v] + 1

																			a__					   =		self.depth_first_search(a_	,	a_	,	a_		)
																			while p:
																							flow += p
																							a__					   =		self.depth_first_search(a_	,	a_	,	a_		)

																			if not self.lvl[sink]:
																							break

											return flow




UpperCAmelCase							=       Dinic(10)
UpperCAmelCase							=       0
UpperCAmelCase							=       9
for vertex in range(1, 5):
	graph.add_edge(source, vertex, 1)
for vertex in range(5, 9):
	graph.add_edge(vertex, sink, 1)
for vertex in range(1, 5):
	graph.add_edge(vertex, vertex + 4, 1)

# Now we can know that is the maximum flow(source -> sink)
print(graph.max_flow(source, sink))









"""simple docstring"""


from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers import (
       TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
       TFXLMForMultipleChoice,
       TFXLMForQuestionAnsweringSimple,
       TFXLMForSequenceClassification,
       TFXLMForTokenClassification,
       TFXLMModel,
       TFXLMWithLMHeadModel,
       XLMConfig,
   )






class 		snake_case    :





    def __init__(				self      :   Union[str, Any]							,						A      :   Optional[Any]							,						):


      '''simple docstring'''




      a	:     Union[str, Any]							=  parent
      a	:     str							=  1_3
      a	:     Optional[int]							=  7
      a	:     List[str]							=  True
      a	:     int							=  True
      a	:     Optional[Any]							=  True
      a	:     Tuple							=  True
      a	:     List[str]							=  True
      a	:     Union[str, Any]							=  False
      a	:     Optional[Any]							=  False
      a	:     List[str]							=  False
      a	:     Union[str, Any]							=  2
      a	:     Optional[int]							=  9_9
      a	:     Optional[Any]							=  0
      a	:     Tuple							=  3_2
      a	:     Union[str, Any]							=  2
      a	:     Optional[Any]							=  4
      a	:     Optional[int]							=  0.1
      a	:     List[str]							=  0.1
      a	:     int							=  5_1_2
      a	:     List[Any]							=  1_6
      a	:     Dict							=  2
      a	:     List[str]							=  0.02
      a	:     str							=  3
      a	:     Optional[Any]							=  4
      a	:     Optional[Any]							=  'last'
      a	:     Any							=  True
      a	:     Union[str, Any]							=  None
      a	:     int							=  0





    def 							lowerCamelCase__ (				self      :   Optional[int]     ):


      '''simple docstring'''




      a	:     Dict							=  ids_tensor([self.batch_size, self.seq_length]							,						self.vocab_size     )
      a	:     Dict							=  random_attention_mask([self.batch_size, self.seq_length]							,						dtype=tf.floataa     )

      a	:     Union[str, Any]							=  None
      if self.use_input_lengths:
        a	:     List[str]							=  (
            ids_tensor([self.batch_size]							,						vocab_size=2     ) + self.seq_length - 2
        )  # small variation of seq_length

      a	:     Optional[Any]							=  None
      if self.use_token_type_ids:
        a	:     str							=  ids_tensor([self.batch_size, self.seq_length]							,						self.n_langs     )

      a	:     Optional[int]							=  None
      a	:     Optional[Any]							=  None
      a	:     Tuple							=  None
      if self.use_labels:
        a	:     Union[str, Any]							=  ids_tensor([self.batch_size]							,						self.type_sequence_label_size     )
        a	:     Any							=  ids_tensor([self.batch_size, self.seq_length]							,						self.num_labels     )
        a	:     Dict							=  ids_tensor([self.batch_size]							,						2							,						dtype=tf.floataa     )
        a	:     Tuple							=  ids_tensor([self.batch_size]							,						self.num_choices     )

      a	:     str							=  XLMConfig(
          vocab_size=self.vocab_size							,						n_special=self.n_special							,						emb_dim=self.hidden_size							,						n_layers=self.num_hidden_layers							,						n_heads=self.num_attention_heads							,						dropout=self.hidden_dropout_prob							,						attention_dropout=self.attention_probs_dropout_prob							,						gelu_activation=self.gelu_activation							,						sinusoidal_embeddings=self.sinusoidal_embeddings							,						asm=self.asm							,						causal=self.causal							,						n_langs=self.n_langs							,						max_position_embeddings=self.max_position_embeddings							,						initializer_range=self.initializer_range							,						summary_type=self.summary_type							,						use_proj=self.use_proj							,						bos_token_id=self.bos_token_id							,						)

      return (
          config,
          input_ids,
          token_type_ids,
          input_lengths,
          sequence_labels,
          token_labels,
          is_impossible_labels,
          choice_labels,
          input_mask,
      )





    def 							lowerCamelCase__ (				self      :   List[str]							,						A      :   Union[str, Any]							,						A      :   Optional[Any]							,						A      :   List[str]							,						A      :   List[Any]							,						A      :   Union[str, Any]							,						A      :   Dict							,						A      :   Optional[int]							,						A      :   List[Any]							,						A      :   Optional[int]							,						):


      '''simple docstring'''




      a	:     int							=  TFXLMModel(config=A     )
      a	:     Optional[Any]							=  {'input_ids': input_ids, 'lengths': input_lengths, 'langs': token_type_ids}
      a	:     Dict							=  model(A     )

      a	:     List[str]							=  [input_ids, input_mask]
      a	:     Union[str, Any]							=  model(A     )
      self.parent.assertEqual(result.last_hidden_state.shape							,						(self.batch_size, self.seq_length, self.hidden_size)     )





    def 							lowerCamelCase__ (				self      :   str							,						A      :   List[Any]							,						A      :   List[Any]							,						A      :   int							,						A      :   int							,						A      :   Any							,						A      :   List[Any]							,						A      :   Tuple							,						A      :   str							,						A      :   List[str]							,						):


      '''simple docstring'''




      a	:     Union[str, Any]							=  TFXLMWithLMHeadModel(A     )

      a	:     str							=  {'input_ids': input_ids, 'lengths': input_lengths, 'langs': token_type_ids}
      a	:     List[str]							=  model(A     )

      a	:     Union[str, Any]							=  outputs

      self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.seq_length, self.vocab_size)     )





    def 							lowerCamelCase__ (				self      :   List[str]							,						A      :   int							,						A      :   List[str]							,						A      :   Tuple							,						A      :   Dict							,						A      :   Dict							,						A      :   str							,						A      :   Union[str, Any]							,						A      :   Optional[Any]							,						A      :   Union[str, Any]							,						):


      '''simple docstring'''




      a	:     Any							=  TFXLMForQuestionAnsweringSimple(A     )

      a	:     Optional[Any]							=  {'input_ids': input_ids, 'lengths': input_lengths}

      a	:     Any							=  model(A     )

      self.parent.assertEqual(result.start_logits.shape							,						(self.batch_size, self.seq_length)     )
      self.parent.assertEqual(result.end_logits.shape							,						(self.batch_size, self.seq_length)     )





    def 							lowerCamelCase__ (				self      :   Optional[int]							,						A      :   Optional[int]							,						A      :   Dict							,						A      :   int							,						A      :   Any							,						A      :   List[Any]							,						A      :   str							,						A      :   List[Any]							,						A      :   Dict							,						A      :   List[str]							,						):


      '''simple docstring'''




      a	:     Dict							=  TFXLMForSequenceClassification(A     )

      a	:     Optional[int]							=  {'input_ids': input_ids, 'lengths': input_lengths}

      a	:     Tuple							=  model(A     )

      self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.type_sequence_label_size)     )





    def 							lowerCamelCase__ (				self      :   int							,						A      :   Optional[Any]							,						A      :   str							,						A      :   Dict							,						A      :   Optional[Any]							,						A      :   List[str]							,						A      :   List[str]							,						A      :   List[Any]							,						A      :   List[Any]							,						A      :   str							,						):


      '''simple docstring'''




      a	:     Any							=  self.num_labels
      a	:     int							=  TFXLMForTokenClassification(config=A     )
      a	:     Union[str, Any]							=  {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
      a	:     int							=  model(A     )
      self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.seq_length, self.num_labels)     )





    def 							lowerCamelCase__ (				self      :   Optional[Any]							,						A      :   Any							,						A      :   Optional[Any]							,						A      :   List[Any]							,						A      :   Dict							,						A      :   List[Any]							,						A      :   Any							,						A      :   List[Any]							,						A      :   List[str]							,						A      :   str							,						):


      '''simple docstring'''




      a	:     Tuple							=  self.num_choices
      a	:     List[str]							=  TFXLMForMultipleChoice(config=A     )
      a	:     List[str]							=  tf.tile(tf.expand_dims(A							,						1     )							,						(1, self.num_choices, 1)     )
      a	:     str							=  tf.tile(tf.expand_dims(A							,						1     )							,						(1, self.num_choices, 1)     )
      a	:     Union[str, Any]							=  tf.tile(tf.expand_dims(A							,						1     )							,						(1, self.num_choices, 1)     )
      a	:     str							=  {
          'input_ids': multiple_choice_inputs_ids,
          'attention_mask': multiple_choice_input_mask,
          'token_type_ids': multiple_choice_token_type_ids,
      }
      a	:     str							=  model(A     )
      self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.num_choices)     )





    def 							lowerCamelCase__ (				self      :   Any     ):


      '''simple docstring'''




      a	:     Union[str, Any]							=  self.prepare_config_and_inputs()
      (
          (
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	
      )	:     Dict							=  config_and_inputs
      a	:     Tuple							=  {
          'input_ids': input_ids,
          'token_type_ids': token_type_ids,
          'langs': token_type_ids,
          'lengths': input_lengths,
      }
      return config, inputs_dict






@require_tf
class 		snake_case    (    UpperCAmelCase  ,					UpperCAmelCase  ,					unittest.TestCase			):
    __magic_name__       	=	(
        (
            TFXLMModel,
            TFXLMWithLMHeadModel,
            TFXLMForSequenceClassification,
            TFXLMForQuestionAnsweringSimple,
            TFXLMForTokenClassification,
            TFXLMForMultipleChoice,
        )
        if is_tf_available()
        else ()
    )
    __magic_name__       	=	(
        (TFXLMWithLMHeadModel,) if is_tf_available() else ()
    )  # TODO (PVP): Check other models whether language generation is also applicable
    __magic_name__       	=	(
        {
            '''feature-extraction''': TFXLMModel,
            '''fill-mask''': TFXLMWithLMHeadModel,
            '''question-answering''': TFXLMForQuestionAnsweringSimple,
            '''text-classification''': TFXLMForSequenceClassification,
            '''text-generation''': TFXLMWithLMHeadModel,
            '''token-classification''': TFXLMForTokenClassification,
            '''zero-shot''': TFXLMForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    __magic_name__       	=	False
    __magic_name__       	=	False





    def 							lowerCamelCase__ (				self      :   Any							,						A      :   List[Any]							,						A      :   Optional[Any]							,						A      :   str							,						A      :   Optional[Any]							,						A      :   List[str]     ):


      '''simple docstring'''




      if (
          pipeline_test_casse_name == "QAPipelineTests"
          and tokenizer_name is not None
          and not tokenizer_name.endswith('Fast'     )
      ):
        # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
        # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
        # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
        return True

      return False





    def 							lowerCamelCase__ (				self      :   int     ):


      '''simple docstring'''




      a	:     str							=  TFXLMModelTester(self     )
      a	:     int							=  ConfigTester(self							,						config_class=A							,						emb_dim=3_7     )





    def 							lowerCamelCase__ (				self      :   str     ):


      '''simple docstring'''




      self.config_tester.run_common_tests()





    def 							lowerCamelCase__ (				self      :   int     ):


      '''simple docstring'''




      a	:     Optional[int]							=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_model(*A     )





    def 							lowerCamelCase__ (				self      :   Union[str, Any]     ):


      '''simple docstring'''




      a	:     Optional[Any]							=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_lm_head(*A     )





    def 							lowerCamelCase__ (				self      :   List[Any]     ):


      '''simple docstring'''




      a	:     Optional[int]							=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_qa(*A     )





    def 							lowerCamelCase__ (				self      :   int     ):


      '''simple docstring'''




      a	:     List[str]							=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_sequence_classif(*A     )





    def 							lowerCamelCase__ (				self      :   Any     ):


      '''simple docstring'''




      a	:     str							=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_for_token_classification(*A     )





    def 							lowerCamelCase__ (				self      :   Tuple     ):


      '''simple docstring'''




      a	:     Tuple							=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_for_multiple_choice(*A     )





    @slow
    def 							lowerCamelCase__ (				self      :   Optional[int]     ):


      '''simple docstring'''




      for model_name in TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        a	:     Any							=  TFXLMModel.from_pretrained(A     )
        self.assertIsNotNone(A     )






@require_tf
class 		snake_case    (    unittest.TestCase			):





    @slow
    def 							lowerCamelCase__ (				self      :   Dict     ):


      '''simple docstring'''




      a	:     List[Any]							=  TFXLMWithLMHeadModel.from_pretrained('xlm-mlm-en-2048'     )
      a	:     Optional[int]							=  tf.convert_to_tensor([[1_4, 4_4_7]]							,						dtype=tf.intaa     )  # the president
      a	:     List[Any]							=  [
          1_4,
          4_4_7,
          1_4,
          4_4_7,
          1_4,
          4_4_7,
          1_4,
          4_4_7,
          1_4,
          4_4_7,
          1_4,
          4_4_7,
          1_4,
          4_4_7,
          1_4,
          4_4_7,
          1_4,
          4_4_7,
          1_4,
          4_4_7,
      ]  # the president the president the president the president the president the president the president the president the president the president
      # TODO(PVP): this and other input_ids I tried for generation give pretty bad results. Not sure why. Model might just not be made for auto-regressive inference
      a	:     Optional[Any]							=  model.generate(A							,						do_sample=A     )
      self.assertListEqual(output_ids[0].numpy().tolist()							,						A     )




