





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  ( _SCREAMING_SNAKE_CASE      )					->  List[str]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		tmp_path / """file.jsonl"""
      SCREAMING_SNAKE_CASE						=		textwrap.dedent(
          """\
        {\"col_1\": -1}
        {\"col_1\": 1, \"col_2\": 2}
        {\"col_1\": 10, \"col_2\": 20}
        """      )
      with open(_SCREAMING_SNAKE_CASE					,		"""w"""      ) as f:
            f.write(_SCREAMING_SNAKE_CASE      )
      return str(_SCREAMING_SNAKE_CASE      )



@pytest.fixture
def   __lowercase  ( _SCREAMING_SNAKE_CASE      )					->  Union[str, Any]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		tmp_path / """file_utf16_encoded.jsonl"""
      SCREAMING_SNAKE_CASE						=		textwrap.dedent(
          """\
        {\"col_1\": -1}
        {\"col_1\": 1, \"col_2\": 2}
        {\"col_1\": 10, \"col_2\": 20}
        """      )
      with open(_SCREAMING_SNAKE_CASE					,		"""w"""					,		encoding="""utf-16"""      ) as f:
            f.write(_SCREAMING_SNAKE_CASE      )
      return str(_SCREAMING_SNAKE_CASE      )



@pytest.fixture
def   __lowercase  ( _SCREAMING_SNAKE_CASE      )					->  Union[str, Any]:


      '''simple docstring'''


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



@pytest.fixture
def   __lowercase  ( _SCREAMING_SNAKE_CASE      )					->  str:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		tmp_path / """file_with_list_of_dicts_field.json"""
      SCREAMING_SNAKE_CASE						=		textwrap.dedent(
          """\
        {
            \"field1\": 1,
            \"field2\": \"aabb\",
            \"field3\": [
                {\"col_1\": -1},
                {\"col_1\": 1, \"col_2\": 2},
                {\"col_1\": 10, \"col_2\": 20}
            ]
        }
        """      )
      with open(_SCREAMING_SNAKE_CASE					,		"""w"""      ) as f:
            f.write(_SCREAMING_SNAKE_CASE      )
      return str(_SCREAMING_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  ( _SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      )					->  Tuple:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		Json(**_SCREAMING_SNAKE_CASE      )
      SCREAMING_SNAKE_CASE						=		json._generate_tables([[request.getfixturevalue(_SCREAMING_SNAKE_CASE      )]]      )
      SCREAMING_SNAKE_CASE						=		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  ( _SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      )					->  Dict:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		Json(**_SCREAMING_SNAKE_CASE      )
      SCREAMING_SNAKE_CASE						=		json._generate_tables([[request.getfixturevalue(_SCREAMING_SNAKE_CASE      )]]      )
      SCREAMING_SNAKE_CASE						=		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]}









import os



def   __lowercase  ( )					->  int:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		os.path.dirname(os.path.realpath(_SCREAMING_SNAKE_CASE      )      )
      SCREAMING_SNAKE_CASE						=		os.path.join(_SCREAMING_SNAKE_CASE					,		"""triangle.txt"""      )

      with open(_SCREAMING_SNAKE_CASE      ) as in_file:
            SCREAMING_SNAKE_CASE						=		[[int(_SCREAMING_SNAKE_CASE      ) for i in line.split()] for line in in_file]

      while len(_SCREAMING_SNAKE_CASE      ) != 1:
            SCREAMING_SNAKE_CASE						=		triangle.pop()
            SCREAMING_SNAKE_CASE						=		triangle[-1]
            for j in range(len(_SCREAMING_SNAKE_CASE      ) - 1      ):
                  curr_row[j] += max(last_row[j]					,		last_row[j + 1]      )
      return triangle[0][0]


if __name__ == "__main__":
      print(solution())


