





import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
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 DetrImageProcessor







class 			__A       (      unittest.TestCase  ):




      """simple docstring"""







      def __init__(		self      ,							a__      ,							a__=7      ,							a__=3      ,							a__=30      ,							a__=400      ,							a__=True      ,							a__=None      ,							a__=True      ,							a__=1 / 255      ,							a__=True      ,							a__=[0.5, 0.5, 0.5]      ,							a__=[0.5, 0.5, 0.5]      ,							a__=True      ,							):



             """simple docstring"""





             _lowerCamelCase							:     Dict	=		size if size is not None else {'''shortest_edge''': 18, '''longest_edge''': 1333}
             _lowerCamelCase							:     Tuple	=		parent
             _lowerCamelCase							:     int	=		batch_size
             _lowerCamelCase							:     Optional[int]	=		num_channels
             _lowerCamelCase							:     Dict	=		min_resolution
             _lowerCamelCase							:     str	=		max_resolution
             _lowerCamelCase							:     Dict	=		do_resize
             _lowerCamelCase							:     Optional[Any]	=		size
             _lowerCamelCase							:     Optional[int]	=		do_rescale
             _lowerCamelCase							:     Any	=		rescale_factor
             _lowerCamelCase							:     List[Any]	=		do_normalize
             _lowerCamelCase							:     Optional[int]	=		image_mean
             _lowerCamelCase							:     Any	=		image_std
             _lowerCamelCase							:     List[str]	=		do_pad


      def 				__snake_case			(		self):



             """simple docstring"""





             return {
                 "do_resize": self.do_resize,
                 "size": self.size,
                 "do_rescale": self.do_rescale,
                 "rescale_factor": self.rescale_factor,
                 "do_normalize": self.do_normalize,
                 "image_mean": self.image_mean,
                 "image_std": self.image_std,
                 "do_pad": self.do_pad,
             }



      def 				__snake_case			(		self      ,							a__      ,							a__=False):



             """simple docstring"""





             if not batched:
                    _lowerCamelCase							:     Optional[Any]	=		image_inputs[0]
                    if isinstance(a__      ,							Image.Image):
                           _lowerCamelCase,  _lowerCamelCase							:     Optional[int]	=		image.size
                    else:
                           _lowerCamelCase,  _lowerCamelCase							:     Any	=		image.shape[1], image.shape[2]
                    if w < h:
                           _lowerCamelCase							:     List[Any]	=		int(self.size['''shortest_edge'''] * h / w)
                           _lowerCamelCase							:     Optional[int]	=		self.size['''shortest_edge''']
                    elif w > h:
                           _lowerCamelCase							:     List[str]	=		self.size['''shortest_edge''']
                           _lowerCamelCase							:     Tuple	=		int(self.size['''shortest_edge'''] * w / h)
                    else:
                           _lowerCamelCase							:     List[Any]	=		self.size['''shortest_edge''']
                           _lowerCamelCase							:     str	=		self.size['''shortest_edge''']

             else:
                    _lowerCamelCase							:     List[Any]	=		[]
                    for image in image_inputs:
                           _lowerCamelCase,  _lowerCamelCase							:     List[Any]	=		self.get_expected_values([image])
                           expected_values.append((expected_height, expected_width))
                    _lowerCamelCase							:     Any	=		max(a__      ,							key=lambda a__: item[0])[0]
                    _lowerCamelCase							:     int	=		max(a__      ,							key=lambda a__: item[1])[1]

             return expected_height, expected_width







@require_torch
@require_vision
class 			__A       (      lowerCamelCase__ ,unittest.TestCase  ):




      """simple docstring"""







      UpperCAmelCase__						=      DetrImageProcessor if is_vision_available() else None


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     Union[str, Any]	=		DetrImageProcessingTester(self)


      @property
      def 				__snake_case			(		self):



             """simple docstring"""





             return self.image_processor_tester.prepare_image_processor_dict()


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     Union[str, Any]	=		self.image_processing_class(**self.image_processor_dict)
             self.assertTrue(hasattr(a__      ,							'''image_mean'''))
             self.assertTrue(hasattr(a__      ,							'''image_std'''))
             self.assertTrue(hasattr(a__      ,							'''do_normalize'''))
             self.assertTrue(hasattr(a__      ,							'''do_rescale'''))
             self.assertTrue(hasattr(a__      ,							'''rescale_factor'''))
             self.assertTrue(hasattr(a__      ,							'''do_resize'''))
             self.assertTrue(hasattr(a__      ,							'''size'''))
             self.assertTrue(hasattr(a__      ,							'''do_pad'''))


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     List[str]	=		self.image_processing_class.from_dict(self.image_processor_dict)
             self.assertEqual(image_processor.size      ,							{'''shortest_edge''': 18, '''longest_edge''': 1333})
             self.assertEqual(image_processor.do_pad      ,							a__)

             _lowerCamelCase							:     int	=		self.image_processing_class.from_dict(
                 self.image_processor_dict      ,							size=42      ,							max_size=84      ,							pad_and_return_pixel_mask=a__)
             self.assertEqual(image_processor.size      ,							{'''shortest_edge''': 42, '''longest_edge''': 84})
             self.assertEqual(image_processor.do_pad      ,							a__)


      def 				__snake_case			(		self):



             """simple docstring"""





             pass


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     Optional[Any]	=		self.image_processing_class(**self.image_processor_dict)
             # create random PIL images
             _lowerCamelCase							:     List[str]	=		prepare_image_inputs(self.image_processor_tester      ,							equal_resolution=a__)
             for image in image_inputs:
                    self.assertIsInstance(a__      ,							Image.Image)

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

             _lowerCamelCase,  _lowerCamelCase							:     Tuple	=		self.image_processor_tester.get_expected_values(a__)

             self.assertEqual(
                 encoded_images.shape      ,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)      ,							)

             # Test batched
             _lowerCamelCase,  _lowerCamelCase							:     Tuple	=		self.image_processor_tester.get_expected_values(a__      ,							batched=a__)

             _lowerCamelCase							:     List[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,
                     expected_height,
                     expected_width,
                 )      ,							)


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     Union[str, Any]	=		self.image_processing_class(**self.image_processor_dict)
             # create random numpy tensors
             _lowerCamelCase							:     List[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
             _lowerCamelCase							:     Tuple	=		image_processing(image_inputs[0]      ,							return_tensors='''pt''').pixel_values

             _lowerCamelCase,  _lowerCamelCase							:     int	=		self.image_processor_tester.get_expected_values(a__)

             self.assertEqual(
                 encoded_images.shape      ,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)      ,							)

             # Test batched
             _lowerCamelCase							:     Dict	=		image_processing(a__      ,							return_tensors='''pt''').pixel_values

             _lowerCamelCase,  _lowerCamelCase							:     List[str]	=		self.image_processor_tester.get_expected_values(a__      ,							batched=a__)

             self.assertEqual(
                 encoded_images.shape      ,							(
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     expected_height,
                     expected_width,
                 )      ,							)


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     Optional[Any]	=		self.image_processing_class(**self.image_processor_dict)
             # create random PyTorch tensors
             _lowerCamelCase							:     Optional[Any]	=		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
             _lowerCamelCase							:     Dict	=		image_processing(image_inputs[0]      ,							return_tensors='''pt''').pixel_values

             _lowerCamelCase,  _lowerCamelCase							:     Optional[int]	=		self.image_processor_tester.get_expected_values(a__)

             self.assertEqual(
                 encoded_images.shape      ,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)      ,							)

             # Test batched
             _lowerCamelCase							:     Tuple	=		image_processing(a__      ,							return_tensors='''pt''').pixel_values

             _lowerCamelCase,  _lowerCamelCase							:     List[str]	=		self.image_processor_tester.get_expected_values(a__      ,							batched=a__)

             self.assertEqual(
                 encoded_images.shape      ,							(
                     self.image_processor_tester.batch_size,
                     self.image_processor_tester.num_channels,
                     expected_height,
                     expected_width,
                 )      ,							)


      @slow
      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     int	=		Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png''')
             with open('''./tests/fixtures/tests_samples/COCO/coco_annotations.txt'''      ,							'''r''') as f:
                    _lowerCamelCase							:     str	=		json.loads(f.read())

             _lowerCamelCase							:     Optional[Any]	=		{'''image_id''': 3_9769, '''annotations''': target}

             # encode them
             _lowerCamelCase							:     Optional[int]	=		DetrImageProcessor.from_pretrained('''facebook/detr-resnet-50''')
             _lowerCamelCase							:     Union[str, Any]	=		image_processing(images=a__      ,							annotations=a__      ,							return_tensors='''pt''')

             # verify pixel values
             _lowerCamelCase							:     Dict	=		torch.Size([1, 3, 800, 1066])
             self.assertEqual(encoding['''pixel_values'''].shape      ,							a__)

             _lowerCamelCase							:     List[Any]	=		torch.tensor([0.2796, 0.3138, 0.3481])
             self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3]      ,							a__      ,							atol=1e-4))

             # verify area
             _lowerCamelCase							:     List[Any]	=		torch.tensor([5887.9600, 1_1250.2061, 48_9353.8438, 83_7122.7500, 14_7967.5156, 16_5732.3438])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''area''']      ,							a__))
             # verify boxes
             _lowerCamelCase							:     Optional[Any]	=		torch.Size([6, 4])
             self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape      ,							a__)
             _lowerCamelCase							:     Any	=		torch.tensor([0.5503, 0.2765, 0.0604, 0.2215])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0]      ,							a__      ,							atol=1e-3))
             # verify image_id
             _lowerCamelCase							:     List[Any]	=		torch.tensor([3_9769])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id''']      ,							a__))
             # verify is_crowd
             _lowerCamelCase							:     Tuple	=		torch.tensor([0, 0, 0, 0, 0, 0])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd''']      ,							a__))
             # verify class_labels
             _lowerCamelCase							:     Optional[Any]	=		torch.tensor([75, 75, 63, 65, 17, 17])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels''']      ,							a__))
             # verify orig_size
             _lowerCamelCase							:     Union[str, Any]	=		torch.tensor([480, 640])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size''']      ,							a__))
             # verify size
             _lowerCamelCase							:     List[Any]	=		torch.tensor([800, 1066])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size''']      ,							a__))



      @slow
      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     Dict	=		Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png''')
             with open('''./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt'''      ,							'''r''') as f:
                    _lowerCamelCase							:     int	=		json.loads(f.read())

             _lowerCamelCase							:     int	=		{'''file_name''': '''000000039769.png''', '''image_id''': 3_9769, '''segments_info''': target}

             _lowerCamelCase							:     List[str]	=		pathlib.Path('''./tests/fixtures/tests_samples/COCO/coco_panoptic''')

             # encode them
             _lowerCamelCase							:     Optional[int]	=		DetrImageProcessor.from_pretrained('''facebook/detr-resnet-50-panoptic''')
             _lowerCamelCase							:     Tuple	=		image_processing(images=a__      ,							annotations=a__      ,							masks_path=a__      ,							return_tensors='''pt''')

             # verify pixel values
             _lowerCamelCase							:     List[Any]	=		torch.Size([1, 3, 800, 1066])
             self.assertEqual(encoding['''pixel_values'''].shape      ,							a__)

             _lowerCamelCase							:     int	=		torch.tensor([0.2796, 0.3138, 0.3481])
             self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3]      ,							a__      ,							atol=1e-4))

             # verify area
             _lowerCamelCase							:     Dict	=		torch.tensor([14_7979.6875, 16_5527.0469, 48_4638.5938, 1_1292.9375, 5879.6562, 7634.1147])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''area''']      ,							a__))
             # verify boxes
             _lowerCamelCase							:     Dict	=		torch.Size([6, 4])
             self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape      ,							a__)
             _lowerCamelCase							:     str	=		torch.tensor([0.2625, 0.5437, 0.4688, 0.8625])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0]      ,							a__      ,							atol=1e-3))
             # verify image_id
             _lowerCamelCase							:     int	=		torch.tensor([3_9769])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id''']      ,							a__))
             # verify is_crowd
             _lowerCamelCase							:     Union[str, Any]	=		torch.tensor([0, 0, 0, 0, 0, 0])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd''']      ,							a__))
             # verify class_labels
             _lowerCamelCase							:     Any	=		torch.tensor([17, 17, 63, 75, 75, 93])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels''']      ,							a__))
             # verify masks
             _lowerCamelCase							:     List[Any]	=		82_2873
             self.assertEqual(encoding['''labels'''][0]['''masks'''].sum().item()      ,							a__)
             # verify orig_size
             _lowerCamelCase							:     Any	=		torch.tensor([480, 640])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size''']      ,							a__))
             # verify size
             _lowerCamelCase							:     int	=		torch.tensor([800, 1066])
             self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size''']      ,							a__))








def    __UpperCAmelCase(      lowercase_ = 10_00      ):
       _lowerCamelCase							:     Optional[int]	=		2**power
       _lowerCamelCase							:     Optional[int]	=		0
       while n:
              _lowerCamelCase,  _lowerCamelCase							:     Optional[Any]	=		r + n % 10, n // 10
       return r


if __name__ == "__main__":
       print(solution(int(str(input()).strip())))

