
import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union

import pandas as pd
import pyarrow as pa

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


if TYPE_CHECKING:
				import sqlitea

				import sqlalchemy


lowercase__				:				Tuple						=      datasets.utils.logging.get_logger(__name__)






@dataclass
class 							SCREAMING_SNAKE_CASE__     (				datasets.BuilderConfig     ):

							"""simple docstring"""






							_snake_case  		=	None
							_snake_case  		=	None
							_snake_case  		=	None
							_snake_case  		=	True
							_snake_case  		=	None
							_snake_case  		=	None
							_snake_case  		=	None
							_snake_case  		=	10000
							_snake_case  		=	None



							def      A__		(	self      )-> Tuple:





													'''simple docstring'''






													if self.sql is None:
																			raise ValueError('''sql must be specified'''      )
													if self.con is None:
																			raise ValueError('''con must be specified'''      )



							def      A__		(	self  ,						SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_ = None  ,						)-> str:





													'''simple docstring'''






													__UpperCamelCase  	=      config_kwargs.copy()
													# We need to stringify the Selectable object to make its hash deterministic

													# The process of stringifying is explained here: http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html
													__UpperCamelCase  	=      config_kwargs['''sql''']
													if not isinstance(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      ):
																			if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
																									import sqlalchemy

																									if isinstance(SCREAMING_SNAKE_CASE_  ,						sqlalchemy.sql.Selectable      ):
																															__UpperCamelCase  	=      sqlalchemy.create_engine(config_kwargs['''con'''].split('''://'''      )[0] + '''://'''      )
																															__UpperCamelCase  	=      str(sql.compile(dialect=engine.dialect      )      )
																															__UpperCamelCase  	=      sql_str
																									else:
																															raise TypeError(
																															    F"Supported types for 'sql' are string and sqlalchemy.sql.Selectable but got {type(SCREAMING_SNAKE_CASE_      )}: {sql}"      )
																			else:
																									raise TypeError(
																									    F"Supported types for 'sql' are string and sqlalchemy.sql.Selectable but got {type(SCREAMING_SNAKE_CASE_      )}: {sql}"      )
													__UpperCamelCase  	=      config_kwargs['''con''']
													if not isinstance(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      ):
																			__UpperCamelCase  	=      id(SCREAMING_SNAKE_CASE_      )
																			logger.info(
																			    F"SQL connection 'con' of type {type(SCREAMING_SNAKE_CASE_      )} couldn't be hashed properly. To enable hashing, specify 'con' as URI string instead."      )

													return super().create_config_id(SCREAMING_SNAKE_CASE_  ,						custom_features=SCREAMING_SNAKE_CASE_      )



							@property
							def      A__		(	self      )-> Tuple:





													'''simple docstring'''






													__UpperCamelCase  	=      {
													    '''index_col''': self.index_col,
													    '''columns''': self.columns,
													    '''params''': self.params,
													    '''coerce_float''': self.coerce_float,
													    '''parse_dates''': self.parse_dates,
													}
													return pd_read_sql_kwargs






class 							SCREAMING_SNAKE_CASE__     (				datasets.ArrowBasedBuilder     ):

							"""simple docstring"""






							_snake_case  		=	SqlConfig



							def      A__		(	self      )-> Optional[int]:





													'''simple docstring'''






													return datasets.DatasetInfo(features=self.config.features      )



							def      A__		(	self  ,						SCREAMING_SNAKE_CASE_      )-> List[Any]:





													'''simple docstring'''






													return [datasets.SplitGenerator(name=datasets.Split.TRAIN  ,						gen_kwargs={}      )]



							def      A__		(	self  ,						SCREAMING_SNAKE_CASE_      )-> pa.Table:





													'''simple docstring'''






													if self.config.features is not None:
																			__UpperCamelCase  	=      self.config.features.arrow_schema
																			if all(not require_storage_cast(SCREAMING_SNAKE_CASE_      ) for feature in self.config.features.values()      ):
																									# cheaper cast
																									__UpperCamelCase  	=      pa.Table.from_arrays([pa_table[field.name] for field in schema]  ,						schema=SCREAMING_SNAKE_CASE_      )
																			else:
																									# more expensive cast; allows str <-> int/float or str to Audio for example
																									__UpperCamelCase  	=      table_cast(SCREAMING_SNAKE_CASE_  ,						SCREAMING_SNAKE_CASE_      )
													return pa_table



							def      A__		(	self      )-> Dict:





													'''simple docstring'''






													__UpperCamelCase  	=      self.config.chunksize
													__UpperCamelCase  	=      pd.read_sql(
													    self.config.sql  ,						self.config.con  ,						chunksize=SCREAMING_SNAKE_CASE_  ,						**self.config.pd_read_sql_kwargs      )
													__UpperCamelCase  	=      [sql_reader] if chunksize is None else sql_reader
													for chunk_idx, df in enumerate(SCREAMING_SNAKE_CASE_      ):
																			__UpperCamelCase  	=      pa.Table.from_pandas(SCREAMING_SNAKE_CASE_      )
																			yield chunk_idx, self._cast_table(SCREAMING_SNAKE_CASE_      )











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


