






import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor

class 				lowerCAmelCase_	(		unittest.TestCase			):


				def __init__(					self ,						_lowerCAmelCase ,						_lowerCAmelCase=7 ,						_lowerCAmelCase=3 ,						_lowerCAmelCase=1_8 ,						_lowerCAmelCase=3_0 ,						_lowerCAmelCase=4_0_0 ,						_lowerCAmelCase=True ,						_lowerCAmelCase=None ,						_lowerCAmelCase=True ,						_lowerCAmelCase=False ,						_lowerCAmelCase=True ,						_lowerCAmelCase=True ,						_lowerCAmelCase=[0.5, 0.5, 0.5] ,						_lowerCAmelCase=[0.5, 0.5, 0.5] ,						):
											_lowercase							:   int 							=   parent
											_lowercase							:   Optional[Any] 							=   batch_size
											_lowercase							:   str 							=   num_channels
											_lowercase							:   Optional[Any] 							=   image_size
											_lowercase							:   List[str] 							=   min_resolution
											_lowercase							:   Optional[Any] 							=   max_resolution
											_lowercase							:   int 							=   do_resize
											_lowercase							:   Tuple 							=   size if size is not None else {'height': 1_8, 'width': 2_0}
											_lowercase							:   List[Any] 							=   do_thumbnail
											_lowercase							:   int 							=   do_align_axis
											_lowercase							:   Any 							=   do_pad
											_lowercase							:   int 							=   do_normalize
											_lowercase							:   List[Any] 							=   image_mean
											_lowercase							:   List[str] 							=   image_std


				def 						__a					(					self      ):
											return {
											    "do_resize": self.do_resize,
											    "size": self.size,
											    "do_thumbnail": self.do_thumbnail,
											    "do_align_long_axis": self.do_align_axis,
											    "do_pad": self.do_pad,
											    "do_normalize": self.do_normalize,
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											}




@require_torch
@require_vision
class 				lowerCAmelCase_	(		__snake_case   ,		unittest.TestCase			):
				_UpperCamelCase					:       Dict							       = DonutImageProcessor if is_vision_available() else None


				def 						__a					(					self      ):
											_lowercase							:   int 							=   DonutImageProcessingTester(self      )


				@property
				def 						__a					(					self      ):
											return self.image_processor_tester.prepare_image_processor_dict()


				def 						__a					(					self      ):
											_lowercase							:   List[Any] 							=   self.image_processing_class(**self.image_processor_dict      )
											self.assertTrue(hasattr(_lowerCAmelCase ,						'do_resize'      )      )
											self.assertTrue(hasattr(_lowerCAmelCase ,						'size'      )      )
											self.assertTrue(hasattr(_lowerCAmelCase ,						'do_thumbnail'      )      )
											self.assertTrue(hasattr(_lowerCAmelCase ,						'do_align_long_axis'      )      )
											self.assertTrue(hasattr(_lowerCAmelCase ,						'do_pad'      )      )
											self.assertTrue(hasattr(_lowerCAmelCase ,						'do_normalize'      )      )
											self.assertTrue(hasattr(_lowerCAmelCase ,						'image_mean'      )      )
											self.assertTrue(hasattr(_lowerCAmelCase ,						'image_std'      )      )


				def 						__a					(					self      ):
											_lowercase							:   Dict 							=   self.image_processing_class.from_dict(self.image_processor_dict      )
											self.assertEqual(image_processor.size ,						{'height': 1_8, 'width': 2_0}      )

											_lowercase							:   List[Any] 							=   self.image_processing_class.from_dict(self.image_processor_dict ,						size=4_2      )
											self.assertEqual(image_processor.size ,						{'height': 4_2, 'width': 4_2}      )

											# Previous config had dimensions in (width, height) order
											_lowercase							:   Any 							=   self.image_processing_class.from_dict(self.image_processor_dict ,						size=(4_2, 8_4)      )
											self.assertEqual(image_processor.size ,						{'height': 8_4, 'width': 4_2}      )


				def 						__a					(					self      ):
											pass


				@is_flaky()
				def 						__a					(					self      ):
											# Initialize image_processing
											_lowercase							:   str 							=   self.image_processing_class(**self.image_processor_dict      )
											# create random PIL images
											_lowercase							:   str 							=   prepare_image_inputs(self.image_processor_tester ,						equal_resolution=_lowerCAmelCase      )
											for image in image_inputs:
																		self.assertIsInstance(_lowerCAmelCase ,						Image.Image      )

											# Test not batched input
											_lowercase							:   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
											_lowercase							:   List[Any] 							=   image_processing(_lowerCAmelCase ,						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'],
											    ) ,						)


				@is_flaky()
				def 						__a					(					self      ):
											# Initialize image_processing
											_lowercase							:   int 							=   self.image_processing_class(**self.image_processor_dict      )
											# create random numpy tensors
											_lowercase							:   int 							=   prepare_image_inputs(self.image_processor_tester ,						equal_resolution=_lowerCAmelCase ,						numpify=_lowerCAmelCase      )
											for image in image_inputs:
																		self.assertIsInstance(_lowerCAmelCase ,						np.ndarray      )

											# Test not batched input
											_lowercase							:   List[str] 							=   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
											_lowercase							:   Any 							=   image_processing(_lowerCAmelCase ,						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'],
											    ) ,						)


				@is_flaky()
				def 						__a					(					self      ):
											# Initialize image_processing
											_lowercase							:   Optional[Any] 							=   self.image_processing_class(**self.image_processor_dict      )
											# create random PyTorch tensors
											_lowercase							:   str 							=   prepare_image_inputs(self.image_processor_tester ,						equal_resolution=_lowerCAmelCase ,						torchify=_lowerCAmelCase      )
											for image in image_inputs:
																		self.assertIsInstance(_lowerCAmelCase ,						torch.Tensor      )

											# Test not batched input
											_lowercase							:   Optional[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
											_lowercase							:   List[Any] 							=   image_processing(_lowerCAmelCase ,						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'],
											    ) ,						)








'''simple docstring'''







def       lowercase					(_A       ):







       """simple docstring"""







       if len(_A       ) <= 1:
              return [tuple(_A       )]

       _lowerCAmelCase     :				List[str]       =							[]

       def generate(_A ,    _A       ):
              _lowerCAmelCase     :				Any       =							[0] * n
              res.append(tuple(_A       )       )

              _lowerCAmelCase     :				Any       =							0
              while i < n:
                     if c[i] < i:
                            if i % 2 == 0:
                                   _lowerCAmelCase      ,  _lowerCAmelCase     :				Tuple       =							arr[i], arr[0]
                            else:
                                   _lowerCAmelCase      ,  _lowerCAmelCase     :				List[str]       =							arr[i], arr[c[i]]
                            res.append(tuple(_A       )       )
                            c[i] += 1
                            _lowerCAmelCase     :				Optional[int]       =							0
                     else:
                            _lowerCAmelCase     :				Any       =							0
                            i += 1

       generate(len(_A       ) ,    _A       )
       return res


if __name__ == "__main__":
       lowerCAmelCase     :  int											=    input("""Enter numbers separated by a comma:\n""").strip()
       lowerCAmelCase     :  Optional[int]											=    [int(item) for item in user_input.split(""",""")]
       print(heaps(arr))

