

import PIL.Image
import PIL.ImageOps
from packaging import version
from PIL import Image


if version.parse(version.parse(PIL.__version__).base_version) >= version.parse("""9.1.0"""):
						lowerCAmelCase							:  str            =						{
						    """linear""": PIL.Image.Resampling.BILINEAR,
						    """bilinear""": PIL.Image.Resampling.BILINEAR,
						    """bicubic""": PIL.Image.Resampling.BICUBIC,
						    """lanczos""": PIL.Image.Resampling.LANCZOS,
						    """nearest""": PIL.Image.Resampling.NEAREST,
						}
else:
						lowerCAmelCase							:  Optional[int]            =						{
						    """linear""": PIL.Image.LINEAR,
						    """bilinear""": PIL.Image.BILINEAR,
						    """bicubic""": PIL.Image.BICUBIC,
						    """lanczos""": PIL.Image.LANCZOS,
						    """nearest""": PIL.Image.NEAREST,
						}







def       A_				(   _UpperCAmelCase   ):
						SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	(images / 2 + 0.5).clamp(0    ,     1   )
						SCREAMING_SNAKE_CASE_:			Union[str, Any]  		=	images.cpu().permute(0    ,     2    ,     3    ,     1   ).float().numpy()
						SCREAMING_SNAKE_CASE_:			List[str]  		=	numpy_to_pil(_UpperCAmelCase   )
						return images







def       A_				(   _UpperCAmelCase   ):
						if images.ndim == 3:
												SCREAMING_SNAKE_CASE_:			Optional[int]  		=	images[None, ...]
						SCREAMING_SNAKE_CASE_:			List[Any]  		=	(images * 2_55).round().astype("uint8"   )
						if images.shape[-1] == 1:
												# special case for grayscale (single channel) images
												SCREAMING_SNAKE_CASE_:			Dict  		=	[Image.fromarray(image.squeeze()    ,     mode="L"   ) for image in images]
						else:
												SCREAMING_SNAKE_CASE_:			Any  		=	[Image.fromarray(_UpperCAmelCase   ) for image in images]

						return pil_images









def       A_				(   _UpperCAmelCase = 10**9   ):
						SCREAMING_SNAKE_CASE_:			List[str]  		=	1
						SCREAMING_SNAKE_CASE_:			Optional[int]  		=	2

						SCREAMING_SNAKE_CASE_:			int  		=	0
						SCREAMING_SNAKE_CASE_:			Dict  		=	0
						SCREAMING_SNAKE_CASE_:			List[str]  		=	0
						while perimeter <= max_perimeter:
												perimeters_sum += perimeter

												prev_value += 2 * value
												value += prev_value

												SCREAMING_SNAKE_CASE_:			Any  		=	2 * value + 2 if i % 2 == 0 else 2 * value - 2
												i += 1

						return perimeters_sum


if __name__ == "__main__":
						print(f'''{solution() = }''')






