



'''simple docstring'''
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 TvltImageProcessor


def   lowercase_	(   lowerCAmelCase__	:  str			,							lowerCAmelCase__	:  Optional[Any]=10			,							lowerCAmelCase__	:  int=10			,							lowerCAmelCase__	:  int=False			,							lowerCAmelCase__	:  Optional[Any]=False ):

			"""simple docstring"""





			__UpperCAmelCase   :      List[Any]										=     []
			for i in range(image_processor_tester.num_frames ):
						video.append(np.random.randint(255			,							size=(image_processor_tester.num_channels, width, height)			,							dtype=np.uinta ) )

			if not numpify and not torchify:
						# PIL expects the channel dimension as last dimension
						__UpperCAmelCase   :      Optional[Any]										=     [Image.fromarray(np.moveaxis(lowerCAmelCase__			,							0			,							-1 ) ) for frame in video]

			if torchify:
						__UpperCAmelCase   :      Optional[Any]										=     [torch.from_numpy(lowerCAmelCase__ ) for frame in video]

			return video


def   lowercase_	(   lowerCAmelCase__	:  Dict			,							lowerCAmelCase__	:  str=False			,							lowerCAmelCase__	:  Optional[Any]=False			,							lowerCAmelCase__	:  List[str]=False ):

			"""simple docstring"""





			assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

			__UpperCAmelCase   :      str										=     []
			for i in range(image_processor_tester.batch_size ):
						if equal_resolution:
									__UpperCAmelCase   :      int										=     image_processor_tester.max_resolution
						else:
									__UpperCAmelCase				,  __UpperCAmelCase   :      Tuple										=     np.random.choice(
									    np.arange(image_processor_tester.min_resolution			,							image_processor_tester.max_resolution )			,							2 )
									__UpperCAmelCase   :      List[str]										=     prepare_video(
									    image_processor_tester=lowerCAmelCase__			,							width=lowerCAmelCase__			,							height=lowerCAmelCase__			,							numpify=lowerCAmelCase__			,							torchify=lowerCAmelCase__			,							)
						video_inputs.append(lowerCAmelCase__ )

			return video_inputs



class _A  (    unittest.TestCase    ):





		def __init__(     self ,       __UpperCAmelCase ,       __UpperCAmelCase=7 ,       __UpperCAmelCase=3 ,       __UpperCAmelCase=4 ,       __UpperCAmelCase=18 ,       __UpperCAmelCase=30 ,       __UpperCAmelCase=400 ,       __UpperCAmelCase=True ,       __UpperCAmelCase=None ,       __UpperCAmelCase=True ,       __UpperCAmelCase=[0.5, 0.5, 0.5] ,       __UpperCAmelCase=[0.5, 0.5, 0.5] ,       __UpperCAmelCase=True ,       __UpperCAmelCase=None ,       )       ->     int:

					'''simple docstring'''
					__UpperCAmelCase   :      Tuple										=     size if size is not None else {"""shortest_edge""": 18}
					__UpperCAmelCase   :      Optional[Any]										=     crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

					__UpperCAmelCase   :      Union[str, Any]										=     parent
					__UpperCAmelCase   :      str										=     batch_size
					__UpperCAmelCase   :      Optional[Any]										=     num_channels
					__UpperCAmelCase   :      int										=     num_frames
					__UpperCAmelCase   :      Tuple										=     image_size
					__UpperCAmelCase   :      Optional[int]										=     min_resolution
					__UpperCAmelCase   :      Any										=     max_resolution
					__UpperCAmelCase   :      Optional[Any]										=     do_resize
					__UpperCAmelCase   :      str										=     size
					__UpperCAmelCase   :      Optional[int]										=     do_normalize
					__UpperCAmelCase   :      Optional[Any]										=     image_mean
					__UpperCAmelCase   :      List[Any]										=     image_std
					__UpperCAmelCase   :      int										=     do_center_crop
					__UpperCAmelCase   :      Tuple										=     crop_size





		def 							__A       (     self				)       ->     Any:

					'''simple docstring'''
					return {
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					    "do_normalize": self.do_normalize,
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "do_center_crop": self.do_center_crop,
					    "crop_size": self.crop_size,
					}



@require_torch
@require_vision
class _A  (    __SCREAMING_SNAKE_CASE	,				unittest.TestCase    ):
		_SCREAMING_SNAKE_CASE					:    str						      =			TvltImageProcessor if is_vision_available() else None





		def 							__A       (     self				)       ->     Dict:

					'''simple docstring'''
					__UpperCAmelCase   :      Dict										=     TvltImageProcessorTester(self				)





		@property
		def 							__A       (     self				)       ->     Union[str, Any]:

					'''simple docstring'''
					return self.image_processor_tester.prepare_image_processor_dict()





		def 							__A       (     self				)       ->     Any:

					'''simple docstring'''
					__UpperCAmelCase   :      Dict										=     self.image_processing_class(**self.image_processor_dict				)
					self.assertTrue(hasattr(__UpperCAmelCase ,       """image_mean"""				)				)
					self.assertTrue(hasattr(__UpperCAmelCase ,       """image_std"""				)				)
					self.assertTrue(hasattr(__UpperCAmelCase ,       """do_normalize"""				)				)
					self.assertTrue(hasattr(__UpperCAmelCase ,       """do_resize"""				)				)
					self.assertTrue(hasattr(__UpperCAmelCase ,       """do_center_crop"""				)				)
					self.assertTrue(hasattr(__UpperCAmelCase ,       """size"""				)				)





		def 							__A       (     self				)       ->     Union[str, Any]:

					'''simple docstring'''
					# Initialize image_processor
					__UpperCAmelCase   :      Tuple										=     self.image_processing_class(**self.image_processor_dict				)
					# create random PIL videos
					__UpperCAmelCase   :      List[Any]										=     prepare_video_inputs(self.image_processor_tester ,       equal_resolution=__UpperCAmelCase				)
					for video in video_inputs:
								self.assertIsInstance(__UpperCAmelCase ,       __UpperCAmelCase				)
								self.assertIsInstance(video[0] ,       Image.Image				)

					# Test not batched input
					__UpperCAmelCase   :      List[str]										=     image_processor(video_inputs[0] ,       return_tensors="""pt"""				).pixel_values
					self.assertEqual(
					    encoded_videos.shape ,       (
					        1,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    ) ,       )

					# Test batched
					__UpperCAmelCase   :      Tuple										=     image_processor(__UpperCAmelCase ,       return_tensors="""pt"""				).pixel_values
					self.assertEqual(
					    encoded_videos.shape ,       (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    ) ,       )





		def 							__A       (     self				)       ->     int:

					'''simple docstring'''
					# Initialize image_processor
					__UpperCAmelCase   :      int										=     self.image_processing_class(**self.image_processor_dict				)
					# create random numpy tensors
					__UpperCAmelCase   :      List[Any]										=     prepare_video_inputs(self.image_processor_tester ,       equal_resolution=__UpperCAmelCase ,       numpify=__UpperCAmelCase				)
					for video in video_inputs:
								self.assertIsInstance(__UpperCAmelCase ,       __UpperCAmelCase				)
								self.assertIsInstance(video[0] ,       np.ndarray				)

					# Test not batched input
					__UpperCAmelCase   :      Union[str, Any]										=     image_processor(video_inputs[0] ,       return_tensors="""pt"""				).pixel_values
					self.assertEqual(
					    encoded_videos.shape ,       (
					        1,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    ) ,       )

					# Test batched
					__UpperCAmelCase   :      Optional[Any]										=     image_processor(__UpperCAmelCase ,       return_tensors="""pt"""				).pixel_values
					self.assertEqual(
					    encoded_videos.shape ,       (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    ) ,       )





		def 							__A       (     self				)       ->     Optional[Any]:

					'''simple docstring'''
					# Initialize image_processor
					__UpperCAmelCase   :      Optional[int]										=     self.image_processing_class(**self.image_processor_dict				)
					# create random PyTorch tensors
					__UpperCAmelCase   :      int										=     prepare_video_inputs(self.image_processor_tester ,       equal_resolution=__UpperCAmelCase ,       torchify=__UpperCAmelCase				)
					for video in video_inputs:
								self.assertIsInstance(__UpperCAmelCase ,       __UpperCAmelCase				)
								self.assertIsInstance(video[0] ,       torch.Tensor				)

					# Test not batched input
					__UpperCAmelCase   :      Optional[Any]										=     image_processor(video_inputs[0] ,       return_tensors="""pt"""				).pixel_values
					self.assertEqual(
					    encoded_videos.shape ,       (
					        1,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    ) ,       )

					# Test batched
					__UpperCAmelCase   :      Union[str, Any]										=     image_processor(__UpperCAmelCase ,       return_tensors="""pt"""				).pixel_values
					self.assertEqual(
					    encoded_videos.shape ,       (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_frames,
					        self.image_processor_tester.num_channels,
					        self.image_processor_tester.crop_size["""height"""],
					        self.image_processor_tester.crop_size["""width"""],
					    ) ,       )









'''simple docstring'''
from itertools import permutations


def   lowercase_	(   lowerCAmelCase__	:  int = 5 ):

			"""simple docstring"""





			if gon_side < 3 or gon_side > 5:
						raise ValueError("""gon_side must be in the range [3, 5]""" )

			# Since it's 16, we know 10 is on the outer ring
			# Put the big numbers at the end so that they are never the first number
			__UpperCAmelCase   :      int										=     list(range(gon_side + 1			,							0			,							-1 ) )
			__UpperCAmelCase   :      int										=     list(range(gon_side + 2			,							gon_side * 2 + 1 ) )

			for perm in permutations(small_numbers + big_numbers ):
						__UpperCAmelCase   :      Optional[int]										=     generate_gon_ring(lowerCAmelCase__			,							list(lowerCAmelCase__ ) )
						if is_magic_gon(lowerCAmelCase__ ):
									return int("""""".join(str(lowerCAmelCase__ ) for n in numbers ) )

			__UpperCAmelCase   :      Optional[int]										=     f'Magic {gon_side}-gon ring is impossible'
			raise ValueError(lowerCAmelCase__ )


def   lowercase_	(   lowerCAmelCase__	:  int			,							lowerCAmelCase__	:  list[int] ):

			"""simple docstring"""





			__UpperCAmelCase   :      Tuple										=     [0] * (gon_side * 3)
			__UpperCAmelCase   :      Optional[Any]										=     perm[0:3]
			perm.append(perm[1] )

			__UpperCAmelCase   :      Union[str, Any]										=     1 if gon_side < 5 else 2

			for i in range(1			,							len(lowerCAmelCase__ ) // 3 + magic_number ):
						__UpperCAmelCase   :      List[str]										=     perm[2 * i + 1]
						__UpperCAmelCase   :      Optional[int]										=     result[3 * i - 1]
						__UpperCAmelCase   :      Optional[int]										=     perm[2 * i + 2]

			return result


def   lowercase_	(   lowerCAmelCase__	:  list[int] ):

			"""simple docstring"""





			if len(lowerCAmelCase__ ) % 3 != 0:
						raise ValueError("""a gon ring should have a length that is a multiple of 3""" )

			if min(numbers[::3] ) != numbers[0]:
						return False

			__UpperCAmelCase   :      Optional[int]										=     sum(numbers[:3] )

			return all(sum(numbers[i : i + 3] ) == total for i in range(3			,							len(lowerCAmelCase__ )			,							3 ) )


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




