


import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import BlipImageProcessor




class  A_ (			unittest.TestCase  ):







 """simple docstring"""





 def __init__(      self       :			Optional[int]							,     _a       :			Optional[Any]							,     _a       :			List[Any]=7							,     _a       :			Union[str, Any]=3							,     _a       :			Any=1_8							,     _a       :			Union[str, Any]=3_0							,     _a       :			Tuple=4_0_0							,     _a       :			Any=True							,     _a       :			Optional[Any]=None							,     _a       :			Optional[Any]=True							,     _a       :			Optional[Any]=False							,     _a       :			Tuple=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]							,     _a       :			Optional[int]=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]							,     _a       :			Tuple=True							,     )     ->      List[str]:
      UpperCAmelCase    :					Union[str, Any]			=      size if size is not None else {"height": 2_0, "width": 2_0}
      UpperCAmelCase    :					Dict			=      parent
      UpperCAmelCase    :					Tuple			=      batch_size
      UpperCAmelCase    :					List[Any]			=      num_channels
      UpperCAmelCase    :					List[str]			=      image_size
      UpperCAmelCase    :					Optional[Any]			=      min_resolution
      UpperCAmelCase    :					int			=      max_resolution
      UpperCAmelCase    :					List[Any]			=      do_resize
      UpperCAmelCase    :					Optional[Any]			=      size
      UpperCAmelCase    :					Tuple			=      do_normalize
      UpperCAmelCase    :					Dict			=      image_mean
      UpperCAmelCase    :					List[str]			=      image_std
      UpperCAmelCase    :					Optional[int]			=      do_pad
      UpperCAmelCase    :					List[str]			=      do_convert_rgb
 def 	_UpperCamelCase     (      self       :			Any					)     ->      List[str]:
      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_normalize": self.do_normalize,
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_convert_rgb": self.do_convert_rgb,
          "do_pad": self.do_pad,
      }

 def 	_UpperCamelCase     (      self       :			Optional[Any]							,     _a       :			Union[str, Any]=False							,     _a       :			str=False							,     _a       :			Optional[int]=False					)     ->      str:
      assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

      if equal_resolution:
           UpperCAmelCase    :					Optional[int]			=      []
           for i in range(self.batch_size					):
                image_inputs.append(
                    np.random.randint(
                        2_5_5							,     size=(self.num_channels, self.max_resolution, self.max_resolution)							,     dtype=np.uinta					)					)
      else:
           UpperCAmelCase    :					Tuple			=      []
           for i in range(self.batch_size					):
                UpperCAmelCase	,			UpperCAmelCase    :					Optional[int]			=      np.random.choice(np.arange(self.min_resolution							,     self.max_resolution					)							,     2					)
                image_inputs.append(np.random.randint(2_5_5							,     size=(self.num_channels, width, height)							,     dtype=np.uinta					)					)

      if not numpify and not torchify:
           # PIL expects the channel dimension as last dimension
           UpperCAmelCase    :					Dict			=      [Image.fromarray(np.moveaxis(_a							,     0							,     -1					)					) for x in image_inputs]

      if torchify:
           UpperCAmelCase    :					str			=      [torch.from_numpy(_a					) for x in image_inputs]

      return image_inputs




@require_torch
@require_vision
class  A_ (			a_   ,    unittest.TestCase  ):







 """simple docstring"""





 _UpperCamelCase					:			int     	=       BlipImageProcessor if is_vision_available() else None
 def 	_UpperCamelCase     (      self       :			str					)     ->      Tuple:
      UpperCAmelCase    :					List[str]			=      BlipImageProcessingTester(self					)
 @property
 def 	_UpperCamelCase     (      self       :			str					)     ->      Dict:
      return self.image_processor_tester.prepare_image_processor_dict()
 def 	_UpperCamelCase     (      self       :			Optional[int]					)     ->      List[Any]:
      UpperCAmelCase    :					Dict			=      self.image_processing_class(**self.image_processor_dict					)
      self.assertTrue(hasattr(_a							,     "do_resize"					)					)
      self.assertTrue(hasattr(_a							,     "size"					)					)
      self.assertTrue(hasattr(_a							,     "do_normalize"					)					)
      self.assertTrue(hasattr(_a							,     "image_mean"					)					)
      self.assertTrue(hasattr(_a							,     "image_std"					)					)
      self.assertTrue(hasattr(_a							,     "do_convert_rgb"					)					)
 def 	_UpperCamelCase     (      self       :			int					)     ->      Optional[Any]:
      pass
 def 	_UpperCamelCase     (      self       :			Tuple					)     ->      List[Any]:
      # Initialize image_processor
      UpperCAmelCase    :					Optional[int]			=      self.image_processing_class(**self.image_processor_dict					)
      # create random PIL images
      UpperCAmelCase    :					Optional[int]			=      self.image_processor_tester.prepare_inputs(equal_resolution=_a					)
      for image in image_inputs:
           self.assertIsInstance(_a							,     Image.Image					)

      # Test not batched input
      UpperCAmelCase    :					Dict			=      image_processor(image_inputs[0]							,     return_tensors="pt"					).pixel_values
      self.assertEqual(
          encoded_images.shape							,     (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )

      # Test batched
      UpperCAmelCase    :					str			=      image_processor(_a							,     return_tensors="pt"					).pixel_values
      self.assertEqual(
          encoded_images.shape							,     (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )
 def 	_UpperCamelCase     (      self       :			Optional[Any]					)     ->      Optional[int]:
      # Initialize image_processor
      UpperCAmelCase    :					Tuple			=      self.image_processing_class(**self.image_processor_dict					)
      # create random numpy tensors
      UpperCAmelCase    :					Union[str, Any]			=      self.image_processor_tester.prepare_inputs(equal_resolution=_a							,     numpify=_a					)
      for image in image_inputs:
           self.assertIsInstance(_a							,     np.ndarray					)

      # Test not batched input
      UpperCAmelCase    :					int			=      image_processor(image_inputs[0]							,     return_tensors="pt"					).pixel_values
      self.assertEqual(
          encoded_images.shape							,     (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )

      # Test batched
      UpperCAmelCase    :					List[Any]			=      image_processor(_a							,     return_tensors="pt"					).pixel_values
      self.assertEqual(
          encoded_images.shape							,     (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )

 def 	_UpperCamelCase     (      self       :			List[Any]					)     ->      Dict:
      # Initialize image_processor
      UpperCAmelCase    :					List[Any]			=      self.image_processing_class(**self.image_processor_dict					)
      # create random PyTorch tensors
      UpperCAmelCase    :					Union[str, Any]			=      self.image_processor_tester.prepare_inputs(equal_resolution=_a							,     torchify=_a					)
      for image in image_inputs:
           self.assertIsInstance(_a							,     torch.Tensor					)

      # Test not batched input
      UpperCAmelCase    :					Any			=      image_processor(image_inputs[0]							,     return_tensors="pt"					).pixel_values
      self.assertEqual(
          encoded_images.shape							,     (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )

      # Test batched
      UpperCAmelCase    :					int			=      image_processor(_a							,     return_tensors="pt"					).pixel_values
      self.assertEqual(
          encoded_images.shape							,     (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )




@require_torch
@require_vision
class  A_ (			a_   ,    unittest.TestCase  ):







 """simple docstring"""





 _UpperCamelCase					:			Union[str, Any]     	=       BlipImageProcessor if is_vision_available() else None
 def 	_UpperCamelCase     (      self       :			Any					)     ->      Union[str, Any]:
      UpperCAmelCase    :					List[Any]			=      BlipImageProcessingTester(self							,     num_channels=4					)
      UpperCAmelCase    :					Tuple			=      3
 @property
 def 	_UpperCamelCase     (      self       :			str					)     ->      int:
      return self.image_processor_tester.prepare_image_processor_dict()
 def 	_UpperCamelCase     (      self       :			List[str]					)     ->      Optional[int]:
      UpperCAmelCase    :					Optional[Any]			=      self.image_processing_class(**self.image_processor_dict					)
      self.assertTrue(hasattr(_a							,     "do_resize"					)					)
      self.assertTrue(hasattr(_a							,     "size"					)					)
      self.assertTrue(hasattr(_a							,     "do_normalize"					)					)
      self.assertTrue(hasattr(_a							,     "image_mean"					)					)
      self.assertTrue(hasattr(_a							,     "image_std"					)					)
      self.assertTrue(hasattr(_a							,     "do_convert_rgb"					)					)
 def 	_UpperCamelCase     (      self       :			Union[str, Any]					)     ->      int:
      pass

 def 	_UpperCamelCase     (      self       :			List[str]					)     ->      Dict:
      # Initialize image_processor
      UpperCAmelCase    :					Optional[Any]			=      self.image_processing_class(**self.image_processor_dict					)
      # create random PIL images
      UpperCAmelCase    :					Optional[Any]			=      self.image_processor_tester.prepare_inputs(equal_resolution=_a					)
      for image in image_inputs:
           self.assertIsInstance(_a							,     Image.Image					)

      # Test not batched input
      UpperCAmelCase    :					List[str]			=      image_processor(image_inputs[0]							,     return_tensors="pt"					).pixel_values
      self.assertEqual(
          encoded_images.shape							,     (
              1,
              self.expected_encoded_image_num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )

      # Test batched
      UpperCAmelCase    :					Tuple			=      image_processor(_a							,     return_tensors="pt"					).pixel_values
      self.assertEqual(
          encoded_images.shape							,     (
              self.image_processor_tester.batch_size,
              self.expected_encoded_image_num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )







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



