


import unittest

import numpy as np
from datasets import load_dataset

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, prepare_image_inputs


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import SegformerImageProcessor




class  A_ (			unittest.TestCase  ):







 """simple docstring"""





 def __init__(      self       :			Optional[Any]							,     _a       :			Dict							,     _a       :			Any=7							,     _a       :			Dict=3							,     _a       :			Optional[Any]=3_0							,     _a       :			List[Any]=4_0_0							,     _a       :			int=True							,     _a       :			str=None							,     _a       :			Optional[Any]=True							,     _a       :			Optional[Any]=[0.5, 0.5, 0.5]							,     _a       :			Any=[0.5, 0.5, 0.5]							,     _a       :			Optional[Any]=False							,     )     ->      Union[str, Any]:
      UpperCAmelCase    :					Optional[Any]			=      size if size is not None else {"height": 3_0, "width": 3_0}
      UpperCAmelCase    :					str			=      parent
      UpperCAmelCase    :					str			=      batch_size
      UpperCAmelCase    :					Any			=      num_channels
      UpperCAmelCase    :					Optional[int]			=      min_resolution
      UpperCAmelCase    :					Tuple			=      max_resolution
      UpperCAmelCase    :					str			=      do_resize
      UpperCAmelCase    :					Union[str, Any]			=      size
      UpperCAmelCase    :					str			=      do_normalize
      UpperCAmelCase    :					Any			=      image_mean
      UpperCAmelCase    :					Optional[Any]			=      image_std
      UpperCAmelCase    :					Optional[Any]			=      do_reduce_labels

 def 	_UpperCamelCase     (      self       :			Dict					)     ->      Optional[Any]:
      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_reduce_labels": self.do_reduce_labels,
      }







def 	A (		):
     UpperCAmelCase    :					List[Any]			=      load_dataset("hf-internal-testing/fixtures_ade20k"		,		split="test"			)

     UpperCAmelCase    :					str			=      Image.open(dataset[0]["file"]			)
     UpperCAmelCase    :					Union[str, Any]			=      Image.open(dataset[1]["file"]			)

     return image, map







def 	A (		):
     UpperCAmelCase    :					Optional[int]			=      load_dataset("hf-internal-testing/fixtures_ade20k"		,		split="test"			)

     UpperCAmelCase    :					Optional[Any]			=      Image.open(dataset[0]["file"]			)
     UpperCAmelCase    :					Optional[int]			=      Image.open(dataset[1]["file"]			)
     UpperCAmelCase    :					Optional[int]			=      Image.open(dataset[2]["file"]			)
     UpperCAmelCase    :					Dict			=      Image.open(dataset[3]["file"]			)

     return [imagea, imagea], [mapa, mapa]




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







 """simple docstring"""





 _UpperCamelCase					:			Any     	=       SegformerImageProcessor if is_vision_available() else None
 def 	_UpperCamelCase     (      self       :			Union[str, Any]					)     ->      Union[str, Any]:
      UpperCAmelCase    :					Optional[int]			=      SegformerImageProcessingTester(self					)
 @property
 def 	_UpperCamelCase     (      self       :			Union[str, Any]					)     ->      Any:
      return self.image_processor_tester.prepare_image_processor_dict()
 def 	_UpperCamelCase     (      self       :			Any					)     ->      List[str]:
      UpperCAmelCase    :					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_reduce_labels"					)					)
 def 	_UpperCamelCase     (      self       :			Dict					)     ->      Union[str, Any]:
      UpperCAmelCase    :					Optional[Any]			=      self.image_processing_class.from_dict(self.image_processor_dict					)
      self.assertEqual(image_processor.size							,     {"height": 3_0, "width": 3_0}					)
      self.assertEqual(image_processor.do_reduce_labels							,     _a					)

      UpperCAmelCase    :					Optional[int]			=      self.image_processing_class.from_dict(self.image_processor_dict							,     size=4_2							,     reduce_labels=_a					)
      self.assertEqual(image_processor.size							,     {"height": 4_2, "width": 4_2}					)
      self.assertEqual(image_processor.do_reduce_labels							,     _a					)
 def 	_UpperCamelCase     (      self       :			int					)     ->      Optional[int]:
      pass
 def 	_UpperCamelCase     (      self       :			Optional[int]					)     ->      Union[str, Any]:
      # Initialize image_processing
      UpperCAmelCase    :					Any			=      self.image_processing_class(**self.image_processor_dict					)
      # create random PIL images
      UpperCAmelCase    :					Optional[Any]			=      prepare_image_inputs(self.image_processor_tester							,     equal_resolution=_a					)
      for image in image_inputs:
           self.assertIsInstance(_a							,     Image.Image					)

      # Test not batched input
      UpperCAmelCase    :					Optional[int]			=      image_processing(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    :					Optional[Any]			=      image_processing(_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       :			int					)     ->      List[Any]:
      # Initialize image_processing
      UpperCAmelCase    :					int			=      self.image_processing_class(**self.image_processor_dict					)
      # create random numpy tensors
      UpperCAmelCase    :					Any			=      prepare_image_inputs(self.image_processor_tester							,     equal_resolution=_a							,     numpify=_a					)
      for image in image_inputs:
           self.assertIsInstance(_a							,     np.ndarray					)

      # Test not batched input
      UpperCAmelCase    :					List[Any]			=      image_processing(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    :					Optional[int]			=      image_processing(_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]					)     ->      List[Any]:
      # Initialize image_processing
      UpperCAmelCase    :					List[str]			=      self.image_processing_class(**self.image_processor_dict					)
      # create random PyTorch tensors
      UpperCAmelCase    :					Tuple			=      prepare_image_inputs(self.image_processor_tester							,     equal_resolution=_a							,     torchify=_a					)
      for image in image_inputs:
           self.assertIsInstance(_a							,     torch.Tensor					)

      # Test not batched input
      UpperCAmelCase    :					Union[str, Any]			=      image_processing(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    :					Optional[int]			=      image_processing(_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[str]					)     ->      List[Any]:
      # Initialize image_processing
      UpperCAmelCase    :					List[Any]			=      self.image_processing_class(**self.image_processor_dict					)
      # create random PyTorch tensors
      UpperCAmelCase    :					int			=      prepare_image_inputs(self.image_processor_tester							,     equal_resolution=_a							,     torchify=_a					)
      UpperCAmelCase    :					Dict			=      []
      for image in image_inputs:
           self.assertIsInstance(_a							,     torch.Tensor					)
           maps.append(torch.zeros(image.shape[-2:]					).long()					)

      # Test not batched input
      UpperCAmelCase    :					List[Any]			=      image_processing(image_inputs[0]							,     maps[0]							,     return_tensors="pt"					)
      self.assertEqual(
          encoding["pixel_values"].shape							,     (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )
      self.assertEqual(
          encoding["labels"].shape							,     (
              1,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )
      self.assertEqual(encoding["labels"].dtype							,     torch.long					)
      self.assertTrue(encoding["labels"].min().item() >= 0					)
      self.assertTrue(encoding["labels"].max().item() <= 2_5_5					)

      # Test batched
      UpperCAmelCase    :					str			=      image_processing(_a							,     _a							,     return_tensors="pt"					)
      self.assertEqual(
          encoding["pixel_values"].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"],
          )							,     )
      self.assertEqual(
          encoding["labels"].shape							,     (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )
      self.assertEqual(encoding["labels"].dtype							,     torch.long					)
      self.assertTrue(encoding["labels"].min().item() >= 0					)
      self.assertTrue(encoding["labels"].max().item() <= 2_5_5					)

      # Test not batched input (PIL images)
      UpperCAmelCase	,			UpperCAmelCase    :					Optional[Any]			=      prepare_semantic_single_inputs()

      UpperCAmelCase    :					Tuple			=      image_processing(_a							,     _a							,     return_tensors="pt"					)
      self.assertEqual(
          encoding["pixel_values"].shape							,     (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )
      self.assertEqual(
          encoding["labels"].shape							,     (
              1,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )
      self.assertEqual(encoding["labels"].dtype							,     torch.long					)
      self.assertTrue(encoding["labels"].min().item() >= 0					)
      self.assertTrue(encoding["labels"].max().item() <= 2_5_5					)

      # Test batched input (PIL images)
      UpperCAmelCase	,			UpperCAmelCase    :					int			=      prepare_semantic_batch_inputs()

      UpperCAmelCase    :					Dict			=      image_processing(_a							,     _a							,     return_tensors="pt"					)
      self.assertEqual(
          encoding["pixel_values"].shape							,     (
              2,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )
      self.assertEqual(
          encoding["labels"].shape							,     (
              2,
              self.image_processor_tester.size["height"],
              self.image_processor_tester.size["width"],
          )							,     )
      self.assertEqual(encoding["labels"].dtype							,     torch.long					)
      self.assertTrue(encoding["labels"].min().item() >= 0					)
      self.assertTrue(encoding["labels"].max().item() <= 2_5_5					)

 def 	_UpperCamelCase     (      self       :			Optional[Any]					)     ->      List[Any]:
      # Initialize image_processing
      UpperCAmelCase    :					Optional[Any]			=      self.image_processing_class(**self.image_processor_dict					)

      # ADE20k has 150 classes, and the background is included, so labels should be between 0 and 150
      UpperCAmelCase	,			UpperCAmelCase    :					str			=      prepare_semantic_single_inputs()
      UpperCAmelCase    :					int			=      image_processing(_a							,     _a							,     return_tensors="pt"					)
      self.assertTrue(encoding["labels"].min().item() >= 0					)
      self.assertTrue(encoding["labels"].max().item() <= 1_5_0					)

      UpperCAmelCase    :					Union[str, Any]			=      True
      UpperCAmelCase    :					List[Any]			=      image_processing(_a							,     _a							,     return_tensors="pt"					)
      self.assertTrue(encoding["labels"].min().item() >= 0					)
      self.assertTrue(encoding["labels"].max().item() <= 2_5_5					)







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



