


from __future__ import annotations

import random
from collections.abc import Iterable
from typing import Any, Generic, TypeVar

_snake_case				=			TypeVar("T", bound=bool)




class  A_ (			Generic[T]  ):







 """simple docstring"""





 def __init__(      self       :			int							,     _a       :			T					)     ->      None:
      UpperCAmelCase    :					T			=      value
      UpperCAmelCase    :					RandomizedHeapNode[T] | None			=      None
      UpperCAmelCase    :					RandomizedHeapNode[T] | None			=      None
 @property
 def 	_UpperCamelCase     (      self       :			List[str]					)     ->      T:
      return self._value

 @staticmethod
 def 	_UpperCamelCase     (      _a       :			RandomizedHeapNode[T] | None							,     _a       :			RandomizedHeapNode[T] | None					)     ->      RandomizedHeapNode[T] | None:
      if not roota:
           return roota

      if not roota:
           return roota

      if roota.value > roota.value:
           UpperCAmelCase	,			UpperCAmelCase    :					str			=      roota, roota

      if random.choice([True, False]					):
           UpperCAmelCase	,			UpperCAmelCase    :					int			=      roota.right, roota.left

      UpperCAmelCase    :					Optional[int]			=      RandomizedHeapNode.merge(roota.left							,     _a					)

      return roota




class  A_ (			Generic[T]  ):







 """simple docstring"""





 def __init__(      self       :			Any							,     _a       :			Iterable[T] | None = ()					)     ->      None:
      UpperCAmelCase    :					RandomizedHeapNode[T] | None			=      None

      if data:
           for item in data:
                self.insert(_a					)
 def 	_UpperCamelCase     (      self       :			Any							,     _a       :			T					)     ->      None:
      UpperCAmelCase    :					List[Any]			=      RandomizedHeapNode.merge(self._root							,     RandomizedHeapNode(_a					)					)
 def 	_UpperCamelCase     (      self       :			Dict					)     ->      T | None:
      UpperCAmelCase    :					Optional[Any]			=      self.top()

      if self._root is None:
           return None

      UpperCAmelCase    :					List[str]			=      RandomizedHeapNode.merge(self._root.left							,     self._root.right					)

      return result
 def 	_UpperCamelCase     (      self       :			Optional[Any]					)     ->      T:
      if not self._root:
           raise IndexError("Can't get top element for the empty heap."					)
      return self._root.value
 def 	_UpperCamelCase     (      self       :			Union[str, Any]					)     ->      None:
      UpperCAmelCase    :					List[Any]			=      None
 def 	_UpperCamelCase     (      self       :			List[str]					)     ->      list[Any]:
      UpperCAmelCase    :					str			=      []
      while self:
           result.append(self.pop()					)

      return result

 def __bool__(      self       :			int					)     ->      bool:
      return self._root is not None


if __name__ == "__main__":
      import doctest

      doctest.testmod()







import os







def 	A (		):
     UpperCAmelCase    :					Any			=      os.path.dirname(os.path.realpath(A__			)			)
     UpperCAmelCase    :					Optional[int]			=      os.path.join(A__		,		"triangle.txt"			)

     with open(A__			) as f:
          UpperCAmelCase    :					Union[str, Any]			=      f.readlines()

     UpperCAmelCase    :					List[str]			=      [[int(A__			) for y in x.rstrip("\r\n"			).split(" "			)] for x in triangle]

     for i in range(1		,		len(A__			)			):
          for j in range(len(a[i]			)			):
               UpperCAmelCase    :					List[Any]			=      a[i - 1][j] if j != len(a[i - 1]			) else 0
               UpperCAmelCase    :					Optional[int]			=      a[i - 1][j - 1] if j > 0 else 0
               a[i][j] += max(A__		,		A__			)
     return max(a[-1]			)


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



