


"""simple docstring"""
import textwrap

import pyarrow as pa
import pytest

from datasets import Features, Value
from datasets.packaged_modules.json.json import Json






@pytest.fixture
def 						lowercase				(	_snake_case		: Tuple	)	->Dict:
	"""simple docstring"""





	__snake_case      :		List[str]         =							tmp_path / '''file.jsonl'''
	__snake_case      :		Optional[Any]         =							textwrap.dedent(
	    '''\
        {"col_1": -1}
        {"col_1": 1, "col_2": 2}
        {"col_1": 10, "col_2": 20}
        '''	)
	with open(_snake_case	,  '''w'''	) as f:
		f.write(_snake_case	)
	return str(_snake_case	)






@pytest.fixture
def 						lowercase				(	_snake_case		: Tuple	)	->Any:
	"""simple docstring"""





	__snake_case      :		List[str]         =							tmp_path / '''file_utf16_encoded.jsonl'''
	__snake_case      :		Dict         =							textwrap.dedent(
	    '''\
        {"col_1": -1}
        {"col_1": 1, "col_2": 2}
        {"col_1": 10, "col_2": 20}
        '''	)
	with open(_snake_case	,  '''w'''	,  encoding='''utf-16'''	) as f:
		f.write(_snake_case	)
	return str(_snake_case	)






@pytest.fixture
def 						lowercase				(	_snake_case		: Tuple	)	->Tuple:
	"""simple docstring"""





	__snake_case      :		Union[str, Any]         =							tmp_path / '''file_with_list_of_dicts.json'''
	__snake_case      :		int         =							textwrap.dedent(
	    '''\
        [
            {"col_1": -1},
            {"col_1": 1, "col_2": 2},
            {"col_1": 10, "col_2": 20}
        ]
        '''	)
	with open(_snake_case	,  '''w'''	) as f:
		f.write(_snake_case	)
	return str(_snake_case	)






@pytest.fixture
def 						lowercase				(	_snake_case		: str	)	->Any:
	"""simple docstring"""





	__snake_case      :		Optional[int]         =							tmp_path / '''file_with_list_of_dicts_field.json'''
	__snake_case      :		Optional[Any]         =							textwrap.dedent(
	    '''\
        {
            "field1": 1,
            "field2": "aabb",
            "field3": [
                {"col_1": -1},
                {"col_1": 1, "col_2": 2},
                {"col_1": 10, "col_2": 20}
            ]
        }
        '''	)
	with open(_snake_case	,  '''w'''	) as f:
		f.write(_snake_case	)
	return str(_snake_case	)






@pytest.mark.parametrize(
    '''file_fixture, config_kwargs'''	,  [
        ('''jsonl_file''', {}),
        ('''jsonl_file_utf16_encoded''', {'''encoding''': '''utf-16'''}),
        ('''json_file_with_list_of_dicts''', {}),
        ('''json_file_with_list_of_dicts_field''', {'''field''': '''field3'''}),
    ]	,  )
def 						lowercase				(	_snake_case		: List[Any]	,  _snake_case		: Tuple	,  _snake_case		: int	)	->int:
	"""simple docstring"""





	__snake_case      :		Any         =							Json(**_snake_case	)
	__snake_case      :		str         =							json._generate_tables([[request.getfixturevalue(_snake_case	)]]	)
	__snake_case      :		str         =							pa.concat_tables([table for _, table in generator]	)
	assert pa_table.to_pydict() == {"col_1": [-1, 1, 10], "col_2": [None, 2, 20]}






@pytest.mark.parametrize(
    '''file_fixture, config_kwargs'''	,  [
        (
            '''jsonl_file''',
            {'''features''': Features({'''col_1''': Value('''int64'''	), '''col_2''': Value('''int64'''	), '''missing_col''': Value('''string'''	)}	)},
        ),
        (
            '''json_file_with_list_of_dicts''',
            {'''features''': Features({'''col_1''': Value('''int64'''	), '''col_2''': Value('''int64'''	), '''missing_col''': Value('''string'''	)}	)},
        ),
        (
            '''json_file_with_list_of_dicts_field''',
            {
                '''field''': '''field3''',
                '''features''': Features(
                    {'''col_1''': Value('''int64'''	), '''col_2''': Value('''int64'''	), '''missing_col''': Value('''string'''	)}	),
            },
        ),
    ]	,  )
def 						lowercase				(	_snake_case		: List[Any]	,  _snake_case		: Tuple	,  _snake_case		: Optional[int]	)	->str:
	"""simple docstring"""





	__snake_case      :		Tuple         =							Json(**_snake_case	)
	__snake_case      :		Optional[Any]         =							json._generate_tables([[request.getfixturevalue(_snake_case	)]]	)
	__snake_case      :		Optional[Any]         =							pa.concat_tables([table for _, table in generator]	)
	assert pa_table.to_pydict() == {"col_1": [-1, 1, 10], "col_2": [None, 2, 20], "missing_col": [None, None, None]}













"""simple docstring"""





UpperCamelCase					=     float("""inf""")







class 						_a  :





   '''simple docstring'''






   def __init__(       self					, UpperCAmelCase_)			->   List[str]:




          '''simple docstring'''




          lowercase__:							Optional[Any]         =     [0] * n
          lowercase__:							Dict         =     [0] * n
          lowercase__:							List[Any]         =     [0] * n
          lowercase__:							str         =     [[] for _ in range(UpperCAmelCase_)]





   def __lowercase							(       self					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_=0)			->   Optional[int]:




          '''simple docstring'''




          self.adj[a].append([b, len(self.adj[b]), c, 0])
          self.adj[b].append([a, len(self.adj[a]) - 1, rcap, 0])





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




          '''simple docstring'''




          if vertex == sink or not flow:
                 return flow

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





   def __lowercase							(       self					, UpperCAmelCase_					, UpperCAmelCase_)			->   str:




          '''simple docstring'''




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

                        lowercase__:							List[str]         =     self.depth_first_search(UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_)
                        while p:
                               flow += p
                               lowercase__:							Any         =     self.depth_first_search(UpperCAmelCase_					, UpperCAmelCase_					, UpperCAmelCase_)

                        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))






