


import unittest
from typing import Dict, List, Optional, Union

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


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import BridgeTowerImageProcessor
class 			_lowercase (     unittest.TestCase			):






				'''simple docstring'''



				def __init__(			self     :str     ,     lowerCAmelCase__     :str     ,     lowerCAmelCase__     :List[Any] = True     ,     lowerCAmelCase__     :int = None     ,     lowerCAmelCase__     :Dict = 32     ,     lowerCAmelCase__     :str = True     ,     lowerCAmelCase__     :int = 1 / 255     ,     lowerCAmelCase__     :Optional[int] = True     ,     lowerCAmelCase__     :str = True     ,     lowerCAmelCase__     :Any = [0.4814_5466, 0.457_8275, 0.4082_1073]     ,     lowerCAmelCase__     :int = [0.2686_2954, 0.2613_0258, 0.2757_7711]     ,     lowerCAmelCase__     :Dict = True     ,     lowerCAmelCase__     :int=7     ,     lowerCAmelCase__     :Dict=30     ,     lowerCAmelCase__     :str=400     ,     lowerCAmelCase__     :Dict=3     ,     )						->     Optional[int]:
										__SCREAMING_SNAKE_CASE		:	List[str]						     =						parent
										__SCREAMING_SNAKE_CASE		:	int						     =						do_resize
										__SCREAMING_SNAKE_CASE		:	Tuple						     =						size if size is not None else {'''shortest_edge''': 288}
										__SCREAMING_SNAKE_CASE		:	List[str]						     =						size_divisor
										__SCREAMING_SNAKE_CASE		:	Any						     =						do_rescale
										__SCREAMING_SNAKE_CASE		:	Optional[Any]						     =						rescale_factor
										__SCREAMING_SNAKE_CASE		:	List[str]						     =						do_normalize
										__SCREAMING_SNAKE_CASE		:	int						     =						do_center_crop
										__SCREAMING_SNAKE_CASE		:	int						     =						image_mean
										__SCREAMING_SNAKE_CASE		:	List[Any]						     =						image_std
										__SCREAMING_SNAKE_CASE		:	Dict						     =						do_pad
										__SCREAMING_SNAKE_CASE		:	List[str]						     =						batch_size
										__SCREAMING_SNAKE_CASE		:	Tuple						     =						num_channels
										__SCREAMING_SNAKE_CASE		:	List[str]						     =						min_resolution
										__SCREAMING_SNAKE_CASE		:	Tuple						     =						max_resolution


				def 						__magic_name__(			self     :Union[str, Any]      )						->     Union[str, Any]:
										return {
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										    "do_normalize": self.do_normalize,
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "size_divisor": self.size_divisor,
										}



				def 						__magic_name__(			self     :Optional[Any]     ,     lowerCAmelCase__     :Tuple     ,     lowerCAmelCase__     :List[Any]=False      )						->     Union[str, Any]:
										if not batched:
																__SCREAMING_SNAKE_CASE		:	Optional[int]						     =						self.size['''shortest_edge''']
																__SCREAMING_SNAKE_CASE		:	Optional[int]						     =						image_inputs[0]
																if isinstance(snake_case_     ,     Image.Image      ):
																						__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	str						     =						image.size
																else:
																						__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	Optional[Any]						     =						image.shape[1], image.shape[2]
																__SCREAMING_SNAKE_CASE		:	Tuple						     =						size / min(snake_case_     ,     snake_case_      )
																if h < w:
																						__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	Dict						     =						size, scale * w
																else:
																						__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	Optional[int]						     =						scale * h, size

																__SCREAMING_SNAKE_CASE		:	Any						     =						int((1_333 / 800) * size      )
																if max(snake_case_     ,     snake_case_      ) > max_size:
																						__SCREAMING_SNAKE_CASE		:	Dict						     =						max_size / max(snake_case_     ,     snake_case_      )
																						__SCREAMING_SNAKE_CASE		:	List[str]						     =						newh * scale
																						__SCREAMING_SNAKE_CASE		:	int						     =						neww * scale

																__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	Dict						     =						int(newh + 0.5      ), int(neww + 0.5      )
																__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	str						     =						(
																    newh // self.size_divisor * self.size_divisor,
																    neww // self.size_divisor * self.size_divisor,
																)

										else:
																__SCREAMING_SNAKE_CASE		:	Any						     =						[]
																for image in image_inputs:
																						__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	str						     =						self.get_expected_values([image]      )
																						expected_values.append((expected_height, expected_width)      )
																__SCREAMING_SNAKE_CASE		:	List[str]						     =						max(snake_case_     ,     key=lambda lowerCAmelCase__      : item[0]      )[0]
																__SCREAMING_SNAKE_CASE		:	str						     =						max(snake_case_     ,     key=lambda lowerCAmelCase__      : item[1]      )[1]

										return expected_height, expected_width




@require_torch
@require_vision
class 			_lowercase (     A__		,     unittest.TestCase			):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__							:     Tuple         =						BridgeTowerImageProcessor if is_vision_available() else None


				def 						__magic_name__(			self     :List[Any]      )						->     Optional[Any]:
										__SCREAMING_SNAKE_CASE		:	List[str]						     =						BridgeTowerImageProcessingTester(self      )


				@property
				def 						__magic_name__(			self     :Union[str, Any]      )						->     Any:
										return self.image_processor_tester.prepare_image_processor_dict()


				def 						__magic_name__(			self     :Optional[Any]      )						->     Optional[int]:
										__SCREAMING_SNAKE_CASE		:	Any						     =						self.image_processing_class(**self.image_processor_dict      )
										self.assertTrue(hasattr(snake_case_     ,     '''image_mean'''      )      )
										self.assertTrue(hasattr(snake_case_     ,     '''image_std'''      )      )
										self.assertTrue(hasattr(snake_case_     ,     '''do_normalize'''      )      )
										self.assertTrue(hasattr(snake_case_     ,     '''do_resize'''      )      )
										self.assertTrue(hasattr(snake_case_     ,     '''size'''      )      )
										self.assertTrue(hasattr(snake_case_     ,     '''size_divisor'''      )      )


				def 						__magic_name__(			self     :Union[str, Any]      )						->     Optional[int]:
										pass


				def 						__magic_name__(			self     :Any      )						->     str:
										# Initialize image processor
										__SCREAMING_SNAKE_CASE		:	int						     =						self.image_processing_class(**self.image_processor_dict      )
										# create random PIL images
										__SCREAMING_SNAKE_CASE		:	Union[str, Any]						     =						prepare_image_inputs(self.image_processor_tester     ,     equal_resolution=snake_case_      )
										for image in image_inputs:
																self.assertIsInstance(snake_case_     ,     Image.Image      )

										# Test not batched input
										__SCREAMING_SNAKE_CASE		:	List[Any]						     =						image_processing(image_inputs[0]     ,     return_tensors='''pt'''      ).pixel_values

										__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	Optional[Any]						     =						self.image_processor_tester.get_expected_values(snake_case_      )
										self.assertEqual(
										    encoded_images.shape     ,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,     )

										# Test batched
										__SCREAMING_SNAKE_CASE		:	Optional[int]						     =						image_processing(snake_case_     ,     return_tensors='''pt'''      ).pixel_values

										__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	Any						     =						self.image_processor_tester.get_expected_values(snake_case_     ,     batched=snake_case_      )
										self.assertEqual(
										    encoded_images.shape     ,     (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )     ,     )


				def 						__magic_name__(			self     :Tuple      )						->     Any:
										# Initialize image processor
										__SCREAMING_SNAKE_CASE		:	List[str]						     =						self.image_processing_class(**self.image_processor_dict      )
										# create random numpy tensors
										__SCREAMING_SNAKE_CASE		:	Optional[int]						     =						prepare_image_inputs(self.image_processor_tester     ,     equal_resolution=snake_case_     ,     numpify=snake_case_      )
										for image in image_inputs:
																self.assertIsInstance(snake_case_     ,     np.ndarray      )

										# Test not batched input
										__SCREAMING_SNAKE_CASE		:	List[str]						     =						image_processing(image_inputs[0]     ,     return_tensors='''pt'''      ).pixel_values

										__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	Optional[int]						     =						self.image_processor_tester.get_expected_values(snake_case_      )
										self.assertEqual(
										    encoded_images.shape     ,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,     )

										# Test batched
										__SCREAMING_SNAKE_CASE		:	Union[str, Any]						     =						image_processing(snake_case_     ,     return_tensors='''pt'''      ).pixel_values

										__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	List[str]						     =						self.image_processor_tester.get_expected_values(snake_case_     ,     batched=snake_case_      )
										self.assertEqual(
										    encoded_images.shape     ,     (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )     ,     )



				def 						__magic_name__(			self     :List[str]      )						->     Dict:
										# Initialize image processor
										__SCREAMING_SNAKE_CASE		:	Union[str, Any]						     =						self.image_processing_class(**self.image_processor_dict      )
										# create random PyTorch tensors
										__SCREAMING_SNAKE_CASE		:	Dict						     =						prepare_image_inputs(self.image_processor_tester     ,     equal_resolution=snake_case_     ,     torchify=snake_case_      )
										for image in image_inputs:
																self.assertIsInstance(snake_case_     ,     torch.Tensor      )

										# Test not batched input
										__SCREAMING_SNAKE_CASE		:	Tuple						     =						image_processing(image_inputs[0]     ,     return_tensors='''pt'''      ).pixel_values

										__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	Dict						     =						self.image_processor_tester.get_expected_values(snake_case_      )
										self.assertEqual(
										    encoded_images.shape     ,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,     )

										# Test batched
										__SCREAMING_SNAKE_CASE		:	Any						     =						image_processing(snake_case_     ,     return_tensors='''pt'''      ).pixel_values

										__SCREAMING_SNAKE_CASE     ,     __SCREAMING_SNAKE_CASE		:	int						     =						self.image_processor_tester.get_expected_values(snake_case_     ,     batched=snake_case_      )
										self.assertEqual(
										    encoded_images.shape     ,     (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )     ,     )


"""simple docstring"""
import os

def  lowercase     ():
						with open(os.path.dirname(_lowerCAmelCase						) + """/grid.txt"""						) as f:
												__lowerCAmelCase     =  []  # noqa: E741
												for _ in range(20						):
																		l.append([int(_lowerCAmelCase						) for x in f.readline().split()]						)

												__lowerCAmelCase     =  0

												# right
												for i in range(20						):
																		for j in range(17						):
																								__lowerCAmelCase     =  l[i][j] * l[i][j + 1] * l[i][j + 2] * l[i][j + 3]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp

        # down
												for i in range(17						):
																		for j in range(20						):
																								__lowerCAmelCase     =  l[i][j] * l[i + 1][j] * l[i + 2][j] * l[i + 3][j]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp

        # diagonal 1
												for i in range(17						):
																		for j in range(17						):
																								__lowerCAmelCase     =  l[i][j] * l[i + 1][j + 1] * l[i + 2][j + 2] * l[i + 3][j + 3]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp

        # diagonal 2
												for i in range(17						):
																		for j in range(3 ,    20						):
																								__lowerCAmelCase     =  l[i][j] * l[i + 1][j - 1] * l[i + 2][j - 2] * l[i + 3][j - 3]
																								if temp > maximum:
																														__lowerCAmelCase     =  temp
												return maximum


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