




class 		lowercase							:

     def __init__(						self	,  _a	,  _a	,  _a       )		->							Optional[int]:
          _A							:  Optional[int]    =		None
          _A							:  Any    =		None
          _A							:  List[str]    =		graph

          self._normalize_graph(_a	,  _a       )
          _A							:  Tuple    =		len(_a       )
          _A							:  Dict    =		None

     def       a__			(						self	,  _a	,  _a       )		->							int:
          if sources is int:
               _A							:  Optional[Any]    =		[sources]
          if sinks is int:
               _A							:  str    =		[sinks]

          if len(_a       ) == 0 or len(_a       ) == 0:
               return

          _A							:  Any    =		sources[0]
          _A							:  Any    =		sinks[0]

          # make fake vertex if there are more
          # than one source or sink
          if len(_a       ) > 1 or len(_a       ) > 1:
               _A							:  int    =		0
               for i in sources:
                    max_input_flow += sum(self.graph[i]       )

               _A							:  int    =		len(self.graph       ) + 1
               for room in self.graph:
                    room.insert(0	,  0       )
               self.graph.insert(0	,  [0] * size       )
               for i in sources:
                    _A							:  List[str]    =		max_input_flow
               _A							:  Any    =		0

               _A							:  Dict    =		len(self.graph       ) + 1
               for room in self.graph:
                    room.append(0       )
               self.graph.append([0] * size       )
               for i in sinks:
                    _A							:  List[Any]    =		max_input_flow
               _A							:  Tuple    =		size - 1

     def       a__			(						self       )		->							int:
          if self.maximum_flow_algorithm is None:
               raise Exception("""You need to set maximum flow algorithm before."""       )
          if self.source_index is None or self.sink_index is None:
               return 0

          self.maximum_flow_algorithm.execute()
          return self.maximum_flow_algorithm.getMaximumFlow()



     def       a__			(						self	,  _a       )		->							Optional[Any]:
          _A							:  Union[str, Any]    =		algorithm(self       )







class 		lowercase							:

     def __init__(						self	,  _a       )		->							List[str]:
          _A							:  str    =		flow_network
          _A							:  int    =		flow_network.verticesCount
          _A							:  Optional[Any]    =		flow_network.sourceIndex
          _A							:  List[str]    =		flow_network.sinkIndex
          # it's just a reference, so you shouldn't change
          # it in your algorithms, use deep copy before doing that
          _A							:  List[str]    =		flow_network.graph
          _A							:  Tuple    =		False

     def       a__			(						self       )		->							Union[str, Any]:
          if not self.executed:
               self._algorithm()
               _A							:  List[Any]    =		True



     def       a__			(						self       )		->							Dict:
          pass







class 		lowercase							(     UpperCamelCase__	):

     def __init__(						self	,  _a       )		->							Dict:
          super().__init__(_a       )
          # use this to save your result
          _A							:  str    =		-1



     def       a__			(						self       )		->							Tuple:
          if not self.executed:
               raise Exception("""You should execute algorithm before using its result!"""       )

          return self.maximum_flow







class 		lowercase							(     UpperCamelCase__	):

     def __init__(						self	,  _a       )		->							List[Any]:
          super().__init__(_a       )

          _A							:  int    =		[[0] * self.verticies_count for i in range(self.verticies_count       )]

          _A							:  str    =		[0] * self.verticies_count
          _A							:  Any    =		[0] * self.verticies_count

     def       a__			(						self       )		->							Any:
          _A							:  str    =		self.verticies_count

          # push some substance to graph
          for nextvertex_index, bandwidth in enumerate(self.graph[self.source_index]       ):
               self.preflow[self.source_index][nextvertex_index] += bandwidth
               self.preflow[nextvertex_index][self.source_index] -= bandwidth
               self.excesses[nextvertex_index] += bandwidth

          # Relabel-to-front selection rule
          _A							:  Tuple    =		[
              i
              for i in range(self.verticies_count       )
              if i != self.source_index and i != self.sink_index
          ]

          # move through list
          _A							:  List[Any]    =		0
          while i < len(_a       ):
               _A							:  List[str]    =		vertices_list[i]
               _A							:  str    =		self.heights[vertex_index]
               self.process_vertex(_a       )
               if self.heights[vertex_index] > previous_height:
                    # if it was relabeled, swap elements
                    # and start from 0 index
                    vertices_list.insert(0	,  vertices_list.pop(_a       )       )
                    _A							:  int    =		0
               else:
                    i += 1

          _A							:  List[str]    =		sum(self.preflow[self.source_index]       )

     def       a__			(						self	,  _a       )		->							Tuple:
          while self.excesses[vertex_index] > 0:
               for neighbour_index in range(self.verticies_count       ):
                    # if it's neighbour and current vertex is higher
                    if (
                        self.graph[vertex_index][neighbour_index]
                        - self.preflow[vertex_index][neighbour_index]
                        > 0
                        and self.heights[vertex_index] > self.heights[neighbour_index]
                    ):
                         self.push(_a	,  _a       )

               self.relabel(_a       )

     def       a__			(						self	,  _a	,  _a       )		->							Tuple:
          _A							:  str    =		min(
              self.excesses[from_index]	,  self.graph[from_index][to_index] - self.preflow[from_index][to_index]	,  )
          self.preflow[from_index][to_index] += preflow_delta
          self.preflow[to_index][from_index] -= preflow_delta
          self.excesses[from_index] -= preflow_delta
          self.excesses[to_index] += preflow_delta



     def       a__			(						self	,  _a       )		->							Dict:
          _A							:  Optional[Any]    =		None
          for to_index in range(self.verticies_count       ):
               if (
                   self.graph[vertex_index][to_index]
                   - self.preflow[vertex_index][to_index]
                   > 0
               ) and (min_height is None or self.heights[to_index] < min_height):
                    _A							:  Optional[int]    =		self.heights[to_index]

          if min_height is not None:
               _A							:  str    =		min_height + 1


if __name__ == "__main__":
  _snake_case            = [0]
  _snake_case            = [3]
  # graph = [
  #     [0, 0, 4, 6, 0, 0],
  #     [0, 0, 5, 2, 0, 0],
  #     [0, 0, 0, 0, 4, 4],
  #     [0, 0, 0, 0, 6, 6],
  #     [0, 0, 0, 0, 0, 0],
  #     [0, 0, 0, 0, 0, 0],
  # ]
  _snake_case            = [[0, 7, 0, 0], [0, 0, 6, 0], [0, 0, 0, 8], [9, 0, 0, 0]]

  # prepare our network
  _snake_case            = FlowNetwork(graph, entrances, exits)
  # set algorithm
  flow_network.set_maximum_flow_algorithm(PushRelabelExecutor)
  # and calculate
  _snake_case            = flow_network.find_maximum_flow()

  print(f"""maximum flow is {maximum_flow}""")







import os
import re
import shutil
import sys
import tempfile
import unittest

import black


_snake_case            = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, "utils"))

import check_copies  # noqa: E402


# This is the reference code that will be used in the tests.
# If BertLMPredictionHead is changed in modeling_bert.py, this code needs to be manually updated.
_snake_case            = "    def __init__(self, config):\n        super().__init__()\n        self.transform = BertPredictionHeadTransform(config)\n\n        # The output weights are the same as the input embeddings, but there is\n        # an output-only bias for each token.\n        self.decoder = nn.Linear(config.hidden_size, config.vocab_size, bias=False)\n\n        self.bias = nn.Parameter(torch.zeros(config.vocab_size))\n\n        # Need a link between the two variables so that the bias is correctly resized with `resize_token_embeddings`\n        self.decoder.bias = self.bias\n\n    def forward(self, hidden_states):\n        hidden_states = self.transform(hidden_states)\n        hidden_states = self.decoder(hidden_states)\n        return hidden_states\n"







class 		lowercase							(     unittest.TestCase	):

     def       a__			(						self       )		->							Union[str, Any]:
           _A							:  List[str]    =		tempfile.mkdtemp()
           os.makedirs(os.path.join(self.transformer_dir	,  """models/bert/"""       )       )
           _A							:  str    =		self.transformer_dir
           shutil.copy(
               os.path.join(_a	,  """src/transformers/models/bert/modeling_bert.py"""       )	,  os.path.join(self.transformer_dir	,  """models/bert/modeling_bert.py"""       )	,  )

     def       a__			(						self       )		->							Optional[int]:
           _A							:  List[str]    =		"""src/transformers"""
           shutil.rmtree(self.transformer_dir       )

     def       a__			(						self	,  _a	,  _a	,  _a	,  _a=None       )		->							Optional[Any]:
           _A							:  Optional[Any]    =		comment + F'''\nclass {class_name}(nn.Module):\n''' + class_code
           if overwrite_result is not None:
                 _A							:  List[str]    =		comment + F'''\nclass {class_name}(nn.Module):\n''' + overwrite_result
           _A							:  List[str]    =		black.Mode(target_versions={black.TargetVersion.PYaa}	,  line_length=119       )
           _A							:  Optional[int]    =		black.format_str(_a	,  mode=_a       )
           _A							:  Optional[Any]    =		os.path.join(self.transformer_dir	,  """new_code.py"""       )
           with open(_a	,  """w"""	,  newline="""\n"""       ) as f:
                 f.write(_a       )
           if overwrite_result is None:
                 self.assertTrue(len(check_copies.is_copy_consistent(_a       )       ) == 0       )
           else:
                 check_copies.is_copy_consistent(f.name	,  overwrite=_a       )
                 with open(_a	,  """r"""       ) as f:
                       self.assertTrue(f.read()	,  _a       )

     def       a__			(						self       )		->							str:
           _A							:  Union[str, Any]    =		check_copies.find_code_in_transformers("""models.bert.modeling_bert.BertLMPredictionHead"""       )
           self.assertEqual(_a	,  _a       )

     def       a__			(						self       )		->							int:
           # Base copy consistency
           self.check_copy_consistency(
               """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead"""	,  """BertLMPredictionHead"""	,  REFERENCE_CODE + """\n"""	,  )

           # With no empty line at the end
           self.check_copy_consistency(
               """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead"""	,  """BertLMPredictionHead"""	,  _a	,  )

           # Copy consistency with rename
           self.check_copy_consistency(
               """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->TestModel"""	,  """TestModelLMPredictionHead"""	,  re.sub("""Bert"""	,  """TestModel"""	,  _a       )	,  )

           # Copy consistency with a really long name
           _A							:  List[str]    =		"""TestModelWithAReallyLongNameBecauseSomePeopleLikeThatForSomeReason"""
           self.check_copy_consistency(
               F'''# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->{long_class_name}'''	,  F'''{long_class_name}LMPredictionHead'''	,  re.sub("""Bert"""	,  _a	,  _a       )	,  )

           # Copy consistency with overwrite
           self.check_copy_consistency(
               """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->TestModel"""	,  """TestModelLMPredictionHead"""	,  _a	,  overwrite_result=re.sub("""Bert"""	,  """TestModel"""	,  _a       )	,  )



     def       a__			(						self       )		->							Tuple:
           _A							:  Union[str, Any]    =		check_copies.LOCALIZED_READMES["""README_zh-hans.md"""]

           _A							:  str    =		(
               """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (from Google Research and the"""
               """ Toyota Technological Institute at Chicago) released with the paper [ALBERT: A Lite BERT for"""
               """ Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942), by Zhenzhong"""
               """ Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut.\n1."""
               """ **[DistilBERT](https://huggingface.co/transformers/model_doc/distilbert.html)** (from HuggingFace),"""
               """ released together with the paper [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and"""
               """ lighter](https://arxiv.org/abs/1910.01108) by Victor Sanh, Lysandre Debut and Thomas Wolf. The same"""
               """ method has been applied to compress GPT2 into"""
               """ [DistilGPT2](https://github.com/huggingface/transformers/tree/main/examples/distillation), RoBERTa into"""
               """ [DistilRoBERTa](https://github.com/huggingface/transformers/tree/main/examples/distillation),"""
               """ Multilingual BERT into"""
               """ [DistilmBERT](https://github.com/huggingface/transformers/tree/main/examples/distillation) and a German"""
               """ version of DistilBERT.\n1. **[ELECTRA](https://huggingface.co/transformers/model_doc/electra.html)**"""
               """ (from Google Research/Stanford University) released with the paper [ELECTRA: Pre-training text encoders"""
               """ as discriminators rather than generators](https://arxiv.org/abs/2003.10555) by Kevin Clark, Minh-Thang"""
               """ Luong, Quoc V. Le, Christopher D. Manning."""
           )
           _A							:  str    =		(
               """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"""
               """ Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
               """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
               """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"""
           )
           _A							:  Any    =		(
               """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"""
               """ Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
               """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
               """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n1."""
               """ **[DistilBERT](https://huggingface.co/transformers/model_doc/distilbert.html)** (来自 HuggingFace) 伴随论文"""
               """ [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and"""
               """ lighter](https://arxiv.org/abs/1910.01108) 由 Victor Sanh, Lysandre Debut and Thomas Wolf 发布。 The same"""
               """ method has been applied to compress GPT2 into"""
               """ [DistilGPT2](https://github.com/huggingface/transformers/tree/main/examples/distillation), RoBERTa into"""
               """ [DistilRoBERTa](https://github.com/huggingface/transformers/tree/main/examples/distillation),"""
               """ Multilingual BERT into"""
               """ [DistilmBERT](https://github.com/huggingface/transformers/tree/main/examples/distillation) and a German"""
               """ version of DistilBERT.\n1. **[ELECTRA](https://huggingface.co/transformers/model_doc/electra.html)** (来自"""
               """ Google Research/Stanford University) 伴随论文 [ELECTRA: Pre-training text encoders as discriminators rather"""
               """ than generators](https://arxiv.org/abs/2003.10555) 由 Kevin Clark, Minh-Thang Luong, Quoc V. Le,"""
               """ Christopher D. Manning 发布。\n"""
           )

           _A    ,     _A							:  Tuple    =		check_copies.convert_to_localized_md(
               _a	,  _a	,  localized_readme["""format_model_list"""]       )

           self.assertFalse(_a       )
           self.assertEqual(_a	,  _a       )

           _A    ,     _A							:  List[str]    =		check_copies.convert_to_localized_md(
               _a	,  _a	,  localized_readme["""format_model_list"""]       )

           # Check whether the number of models is equal to README.md after conversion.
           self.assertTrue(_a       )

           _A							:  Tuple    =		(
               """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (from Google Research and the"""
               """ Toyota Technological Institute at Chicago) released with the paper [ALBERT: A Lite BERT for"""
               """ Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942), by Zhenzhong"""
               """ Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut."""
           )
           _A							:  Dict    =		(
               """1. **[ALBERT](https://huggingface.co/transformers/main/model_doc/albert.html)** (来自 Google Research and"""
               """ the Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
               """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
               """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"""
           )
           _A							:  Optional[Any]    =		(
               """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"""
               """ Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
               """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
               """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"""
           )

           _A    ,     _A							:  Optional[int]    =		check_copies.convert_to_localized_md(
               _a	,  _a	,  localized_readme["""format_model_list"""]       )

           # Check if the model link is synchronized.
           self.assertEqual(_a	,  _a       )

