


'''simple docstring'''






import itertools
from dataclasses import dataclass
from io import StringIO
from typing import Optional

import pyarrow as pa

import datasets
from datasets.features.features import require_storage_cast
from datasets.table import table_cast


a_       :     Optional[Any] 							=     datasets.utils.logging.get_logger(__name__)




@dataclass
class 			a  (  datasets.BuilderConfig							):
 _lowerCAmelCase			       =						None
 _lowerCAmelCase			       =						"utf-8"
 _lowerCAmelCase			       =						None
 _lowerCAmelCase			       =						1_0 << 2_0  # 10MB
 _lowerCAmelCase			       =						False
 _lowerCAmelCase			       =						"line"





class 			a  (  datasets.ArrowBasedBuilder							):
 _lowerCAmelCase			       =						TextConfig
 def 				__UpperCAmelCase		(			self    )       ->				str:
      return datasets.DatasetInfo(features=self.config.features    )
 def 				__UpperCAmelCase		(			self   ,					__magic_name__    )       ->				str:
      if not self.config.data_files:
           raise ValueError(f'At least one data file must be specified, but got data_files={self.config.data_files}'    )
      _a         =				dl_manager.download_and_extract(self.config.data_files    )
      if isinstance(__magic_name__   ,					(str, list, tuple)    ):
           _a         =				data_files
           if isinstance(__magic_name__   ,					__magic_name__    ):
                _a         =				[files]
           _a         =				[dl_manager.iter_files(__magic_name__    ) for file in files]
           return [datasets.SplitGenerator(name=datasets.Split.TRAIN   ,					gen_kwargs={'files': files}    )]
      _a         =				[]
      for split_name, files in data_files.items():
           if isinstance(__magic_name__   ,					__magic_name__    ):
                _a         =				[files]
           _a         =				[dl_manager.iter_files(__magic_name__    ) for file in files]
           splits.append(datasets.SplitGenerator(name=__magic_name__   ,					gen_kwargs={'files': files}    )    )
      return splits
 def 				__UpperCAmelCase		(			self   ,					__magic_name__    )       ->				pa.Table:
      if self.config.features is not None:
           _a         =				self.config.features.arrow_schema
           if all(not require_storage_cast(__magic_name__    ) for feature in self.config.features.values()    ):
                # cheaper cast
                _a         =				pa_table.cast(__magic_name__    )
           else:
                # more expensive cast; allows str <-> int/float or str to Audio for example
                _a         =				table_cast(__magic_name__   ,					__magic_name__    )
           return pa_table
      else:
           return pa_table.cast(pa.schema({'text': pa.string()}    )    )




 def 				__UpperCAmelCase		(			self   ,					__magic_name__    )       ->				List[str]:
      _a         =				list(self.config.features    ) if self.config.features is not None else ['text']
      for file_idx, file in enumerate(itertools.chain.from_iterable(__magic_name__    )    ):
           # open in text mode, by default translates universal newlines ("\n", "\r\n" and "\r") into "\n"
           with open(__magic_name__   ,					encoding=self.config.encoding   ,					errors=self.config.errors    ) as f:
                if self.config.sample_by == "line":
                     _a         =				0
                     while True:
                          _a         =				f.read(self.config.chunksize    )
                          if not batch:
                               break
                          batch += f.readline()  # finish current line
                          # StringIO.readlines, by default splits only on "\n" (and keeps line breaks)
                          _a         =				StringIO(__magic_name__    ).readlines()
                          if not self.config.keep_linebreaks:
                               _a         =				[line.rstrip('\n'    ) for line in batch]
                          _a         =				pa.Table.from_arrays([pa.array(__magic_name__    )]   ,					names=__magic_name__    )
                          # Uncomment for debugging (will print the Arrow table size and elements)
                          # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
                          # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
                          yield (file_idx, batch_idx), self._cast_table(__magic_name__    )
                          batch_idx += 1
                elif self.config.sample_by == "paragraph":
                     _a         =				0
                     _a         =				''
                     while True:
                          _a         =				f.read(self.config.chunksize    )
                          if not new_batch:
                               break
                          batch += new_batch
                          batch += f.readline()  # finish current line
                          _a         =				batch.split('\n\n'    )
                          _a         =				pa.Table.from_arrays(
                              [pa.array([example for example in batch[:-1] if example]    )]   ,					names=__magic_name__    )
                          # Uncomment for debugging (will print the Arrow table size and elements)
                          # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
                          # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
                          yield (file_idx, batch_idx), self._cast_table(__magic_name__    )
                          batch_idx += 1
                          _a         =				batch[-1]
                     if batch:
                          _a         =				pa.Table.from_arrays([pa.array([batch]    )]   ,					names=__magic_name__    )
                          yield (file_idx, batch_idx), self._cast_table(__magic_name__    )
                elif self.config.sample_by == "document":
                     _a         =				f.read()
                     _a         =				pa.Table.from_arrays([pa.array([text]    )]   ,					names=__magic_name__    )
                     yield file_idx, self._cast_table(__magic_name__    )





'''simple docstring'''






import os






def 						_A					() ->	int:




     '''simple docstring'''



     _a         =				os.path.dirname(os.path.realpath(lowerCAmelCase__		)		)
     _a         =				os.path.join(lowerCAmelCase__					,    'triangle.txt'		)

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

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


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

