





from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
      import torch

SCREAMING_SNAKE_CASE_		  =			logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
      from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):



      def   __lowercase  ( cls      )					->  Tuple:


            '''simple docstring'''


            return cls



def   __lowercase  ( _SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE = None					,		_SCREAMING_SNAKE_CASE = None					,		_SCREAMING_SNAKE_CASE = None					,		_SCREAMING_SNAKE_CASE = None					,		)					->  Optional[int]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE						=		device
      SCREAMING_SNAKE_CASE						=		shape[0]

      SCREAMING_SNAKE_CASE						=		layout or torch.strided
      SCREAMING_SNAKE_CASE						=		device or torch.device("""cpu"""      )

      if generator is not None:
            SCREAMING_SNAKE_CASE						=		generator.device.type if not isinstance(_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      ) else generator[0].device.type
            if gen_device_type != device.type and gen_device_type == "cpu":
                  SCREAMING_SNAKE_CASE						=		"""cpu"""
                  if device != "mps":
                        logger.info(
                            F"""The passed generator was created on 'cpu' even though a tensor on {device} was expected."""
                            F""" Tensors will be created on 'cpu' and then moved to {device}. Note that one can probably"""
                            F""" slighly speed up this function by passing a generator that was created on the {device} device."""      )
            elif gen_device_type != device.type and gen_device_type == "cuda":
                  raise ValueError(F"""Cannot generate a {device} tensor from a generator of type {gen_device_type}."""      )

      if isinstance(_SCREAMING_SNAKE_CASE					,		_SCREAMING_SNAKE_CASE      ):
            SCREAMING_SNAKE_CASE						=		(1,) + shape[1:]
            SCREAMING_SNAKE_CASE						=		[
                torch.randn(_SCREAMING_SNAKE_CASE					,		generator=generator[i]					,		device=_SCREAMING_SNAKE_CASE					,		dtype=_SCREAMING_SNAKE_CASE					,		layout=_SCREAMING_SNAKE_CASE      )
                for i in range(_SCREAMING_SNAKE_CASE      )
            ]
            SCREAMING_SNAKE_CASE						=		torch.cat(_SCREAMING_SNAKE_CASE					,		dim=0      ).to(_SCREAMING_SNAKE_CASE      )
      else:
            SCREAMING_SNAKE_CASE						=		torch.randn(_SCREAMING_SNAKE_CASE					,		generator=_SCREAMING_SNAKE_CASE					,		device=_SCREAMING_SNAKE_CASE					,		dtype=_SCREAMING_SNAKE_CASE					,		layout=_SCREAMING_SNAKE_CASE      ).to(_SCREAMING_SNAKE_CASE      )

      return latents



def   __lowercase  ( _SCREAMING_SNAKE_CASE      )					->  Tuple:


      '''simple docstring'''


      if is_torch_version("""<"""					,		"""2.0.0"""      ) or not hasattr(_SCREAMING_SNAKE_CASE					,		"""_dynamo"""      ):
            return False
      return isinstance(_SCREAMING_SNAKE_CASE					,		torch._dynamo.eval_frame.OptimizedModule      )









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


