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


if is_torch_available():
  import torch

if is_vision_available():
  import PIL

  from transformers import FlavaImageProcessor
  from transformers.image_utils import PILImageResampling
  from transformers.models.flava.image_processing_flava import (
      FLAVA_CODEBOOK_MEAN,
      FLAVA_CODEBOOK_STD,
      FLAVA_IMAGE_MEAN,
      FLAVA_IMAGE_STD,
  )
else:
  UpperCAmelCase				 =   UpperCAmelCase				 =   UpperCAmelCase				 =   UpperCAmelCase				 =   None






class 				_SCREAMING_SNAKE_CASE( unittest.TestCase						):
   def __init__(     self				,  lowerCAmelCase_				,  lowerCAmelCase_=7				,  lowerCAmelCase_=3				,  lowerCAmelCase_=30				,  lowerCAmelCase_=4_00				,  lowerCAmelCase_=True				,  lowerCAmelCase_=None				,  lowerCAmelCase_=True				,  lowerCAmelCase_=None				,  lowerCAmelCase_=None				,  lowerCAmelCase_=True				,  lowerCAmelCase_=1 / 2_55				,  lowerCAmelCase_=True				,  lowerCAmelCase_=FLAVA_IMAGE_MEAN				,  lowerCAmelCase_=FLAVA_IMAGE_STD				,  lowerCAmelCase_=14				,  lowerCAmelCase_=75				,  lowerCAmelCase_=None				,  lowerCAmelCase_=16				,  lowerCAmelCase_=0.3				,  lowerCAmelCase_=None				,  lowerCAmelCase_=True				,  lowerCAmelCase_=None				,  lowerCAmelCase_=None				,  lowerCAmelCase_=True				,  lowerCAmelCase_=None				,  lowerCAmelCase_=True				,  lowerCAmelCase_=True				,  lowerCAmelCase_=FLAVA_CODEBOOK_MEAN				,  lowerCAmelCase_=FLAVA_CODEBOOK_STD				,  )						->Union[str, Any]:
        a	:     Dict						      =    size if size is not None else {'''height''': 2_24, '''width''': 2_24}
        a	:     Dict						      =    crop_size if crop_size is not None else {'''height''': 2_24, '''width''': 2_24}
        a	:     List[str]						      =    codebook_size if codebook_size is not None else {'''height''': 1_12, '''width''': 1_12}
        a	:     Dict						      =    codebook_crop_size if codebook_crop_size is not None else {'''height''': 1_12, '''width''': 1_12}

        a	:     Tuple						      =    parent
        a	:     Any						      =    batch_size
        a	:     List[Any]						      =    num_channels
        a	:     str						      =    do_resize
        a	:     Union[str, Any]						      =    do_rescale
        a	:     int						      =    rescale_factor
        a	:     int						      =    min_resolution
        a	:     Optional[int]						      =    max_resolution
        a	:     Optional[int]						      =    size
        a	:     Union[str, Any]						      =    resample if resample is not None else PILImageResampling.BICUBIC
        a	:     Any						      =    do_normalize
        a	:     int						      =    image_mean
        a	:     List[Any]						      =    image_std
        a	:     Tuple						      =    do_center_crop
        a	:     str						      =    crop_size

        a	:     List[Any]						      =    input_size_patches
        a	:     Any						      =    total_mask_patches
        a	:     str						      =    mask_group_max_patches
        a	:     str						      =    mask_group_min_patches
        a	:     str						      =    mask_group_min_aspect_ratio
        a	:     int						      =    mask_group_max_aspect_ratio

        a	:     Tuple						      =    codebook_do_resize
        a	:     int						      =    codebook_size
        a	:     Tuple						      =    codebook_resample if codebook_resample is not None else PILImageResampling.LANCZOS
        a	:     int						      =    codebook_do_center_crop
        a	:     Tuple						      =    codebook_crop_size
        a	:     Optional[Any]						      =    codebook_do_map_pixels
        a	:     Union[str, Any]						      =    codebook_do_normalize
        a	:     Tuple						      =    codebook_image_mean
        a	:     Optional[int]						      =    codebook_image_std
   def _lowercase(     self     )						->Tuple:
        return {
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_normalize": self.do_normalize,
            "do_resize": self.do_resize,
            "size": self.size,
            "resample": self.resample,
            "do_rescale": self.do_rescale,
            "rescale_factor": self.rescale_factor,
            "do_center_crop": self.do_center_crop,
            "crop_size": self.crop_size,
            "input_size_patches": self.input_size_patches,
            "total_mask_patches": self.total_mask_patches,
            "mask_group_max_patches": self.mask_group_max_patches,
            "mask_group_min_patches": self.mask_group_min_patches,
            "mask_group_min_aspect_ratio": self.mask_group_min_aspect_ratio,
            "mask_group_max_aspect_ratio": self.mask_group_min_aspect_ratio,
            "codebook_do_resize": self.codebook_do_resize,
            "codebook_size": self.codebook_size,
            "codebook_resample": self.codebook_resample,
            "codebook_do_center_crop": self.codebook_do_center_crop,
            "codebook_crop_size": self.codebook_crop_size,
            "codebook_do_map_pixels": self.codebook_do_map_pixels,
            "codebook_do_normalize": self.codebook_do_normalize,
            "codebook_image_mean": self.codebook_image_mean,
            "codebook_image_std": self.codebook_image_std,
        }
   def _lowercase(     self     )						->str:
        return (self.size["height"], self.size["width"])
   def _lowercase(     self     )						->int:
        return (
            (self.input_size_patches, self.input_size_patches)
            if not isinstance(self.input_size_patches				,  lowerCAmelCase_     )
            else self.input_size_patches
        )


   def _lowercase(     self     )						->int:
        return (self.codebook_size["height"], self.codebook_size["width"])






@require_torch
@require_vision
class 				_SCREAMING_SNAKE_CASE( snake_case__							,   unittest.TestCase						):
   UpperCamelCase_					:    str			      = FlavaImageProcessor if is_vision_available() else None
   UpperCamelCase_					:    List[str]			      = None
   def _lowercase(     self     )						->List[str]:
        a	:     List[str]						      =    FlavaImageProcessingTester(self     )
   @property
   def _lowercase(     self     )						->Union[str, Any]:
        return self.image_processor_tester.prepare_image_processor_dict()
   def _lowercase(     self     )						->Optional[Any]:
        a	:     str						      =    self.image_processing_class(**self.image_processor_dict     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''image_mean'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''image_std'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''do_normalize'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''do_resize'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''resample'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''crop_size'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''do_center_crop'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''do_rescale'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''rescale_factor'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''masking_generator'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''codebook_do_resize'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''codebook_size'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''codebook_resample'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''codebook_do_center_crop'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''codebook_crop_size'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''codebook_do_map_pixels'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''codebook_do_normalize'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''codebook_image_mean'''     )     )
        self.assertTrue(hasattr(lowerCAmelCase_				,  '''codebook_image_std'''     )     )
   def _lowercase(     self     )						->Any:
        a	:     List[Any]						      =    self.image_processing_class.from_dict(self.image_processor_dict     )
        self.assertEqual(image_processor.size				,  {'''height''': 2_24, '''width''': 2_24}     )
        self.assertEqual(image_processor.crop_size				,  {'''height''': 2_24, '''width''': 2_24}     )
        self.assertEqual(image_processor.codebook_size				,  {'''height''': 1_12, '''width''': 1_12}     )
        self.assertEqual(image_processor.codebook_crop_size				,  {'''height''': 1_12, '''width''': 1_12}     )

        a	:     Union[str, Any]						      =    self.image_processing_class.from_dict(
            self.image_processor_dict				,  size=42				,  crop_size=84				,  codebook_size=33				,  codebook_crop_size=66     )
        self.assertEqual(image_processor.size				,  {'''height''': 42, '''width''': 42}     )
        self.assertEqual(image_processor.crop_size				,  {'''height''': 84, '''width''': 84}     )
        self.assertEqual(image_processor.codebook_size				,  {'''height''': 33, '''width''': 33}     )
        self.assertEqual(image_processor.codebook_crop_size				,  {'''height''': 66, '''width''': 66}     )
   def _lowercase(     self     )						->Optional[Any]:
        pass
   def _lowercase(     self     )						->List[Any]:
        # Initialize image_processing
        a	:     Dict						      =    self.image_processing_class(**self.image_processor_dict     )
        # create random PIL images
        a	:     int						      =    prepare_image_inputs(self.image_processor_tester				,  equal_resolution=lowerCAmelCase_     )
        for image in image_inputs:
             self.assertIsInstance(lowerCAmelCase_				,  PIL.Image.Image     )

        # Test not batched input
        a	:     Union[str, Any]						      =    image_processing(image_inputs[0]				,  return_tensors='''pt'''     )

        # Test no bool masked pos
        self.assertFalse('''bool_masked_pos''' in encoded_images     )

        a      ,				a	:     str						      =    self.image_processor_tester.get_expected_image_size()

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

        # Test batched
        a	:     Optional[Any]						      =    image_processing(lowerCAmelCase_				,  return_tensors='''pt'''     )
        a      ,				a	:     Tuple						      =    self.image_processor_tester.get_expected_image_size()

        # Test no bool masked pos
        self.assertFalse('''bool_masked_pos''' in encoded_images     )

        self.assertEqual(
            encoded_images.pixel_values.shape				,  (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )				,  )
   def _lowercase(     self				,  lowerCAmelCase_				,  lowerCAmelCase_     )						->int:
        # Initialize image_processing
        a	:     str						      =    self.image_processing_class(**self.image_processor_dict     )
        # create random tensors
        a	:     List[str]						      =    prepare_image_inputs(self.image_processor_tester				,  equal_resolution=lowerCAmelCase_				,  **lowerCAmelCase_     )
        for image in image_inputs:
             self.assertIsInstance(lowerCAmelCase_				,  lowerCAmelCase_     )

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

        a      ,				a	:     Optional[Any]						      =    self.image_processor_tester.get_expected_image_size()
        self.assertEqual(
            encoded_images.pixel_values.shape				,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)				,  )

        a	:     Tuple						      =    image_processing(lowerCAmelCase_				,  return_image_mask=lowerCAmelCase_				,  return_tensors='''pt'''     )

        a      ,				a	:     int						      =    self.image_processor_tester.get_expected_image_size()
        self.assertEqual(
            encoded_images.pixel_values.shape				,  (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )				,  )

        a      ,				a	:     Optional[int]						      =    self.image_processor_tester.get_expected_mask_size()
        self.assertEqual(
            encoded_images.bool_masked_pos.shape				,  (
                self.image_processor_tester.batch_size,
                expected_height,
                expected_width,
            )				,  )

        # Test batched
        a	:     str						      =    image_processing(lowerCAmelCase_				,  return_tensors='''pt'''     ).pixel_values

        a      ,				a	:     List[str]						      =    self.image_processor_tester.get_expected_image_size()
        self.assertEqual(
            encoded_images.shape				,  (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )				,  )

        # Test masking
        a	:     Union[str, Any]						      =    image_processing(lowerCAmelCase_				,  return_image_mask=lowerCAmelCase_				,  return_tensors='''pt'''     )

        a      ,				a	:     int						      =    self.image_processor_tester.get_expected_image_size()
        self.assertEqual(
            encoded_images.pixel_values.shape				,  (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )				,  )

        a      ,				a	:     Tuple						      =    self.image_processor_tester.get_expected_mask_size()
        self.assertEqual(
            encoded_images.bool_masked_pos.shape				,  (
                self.image_processor_tester.batch_size,
                expected_height,
                expected_width,
            )				,  )
   def _lowercase(     self     )						->Tuple:
        self._test_call_framework(np.ndarray				,  prepare_kwargs={'''numpify''': True}     )
   def _lowercase(     self     )						->List[str]:
        self._test_call_framework(torch.Tensor				,  prepare_kwargs={'''torchify''': True}     )
   def _lowercase(     self     )						->Any:
        # Initialize image_processing
        random.seed(12_34     )
        a	:     List[str]						      =    self.image_processing_class(**self.image_processor_dict     )
        a	:     str						      =    prepare_image_inputs(self.image_processor_tester				,  equal_resolution=lowerCAmelCase_				,  torchify=lowerCAmelCase_     )

        # Test not batched input
        a	:     Tuple						      =    image_processing(image_inputs[0]				,  return_image_mask=lowerCAmelCase_				,  return_tensors='''pt'''     )
        self.assertEqual(encoded_images.bool_masked_pos.sum().item()				,  75     )


   def _lowercase(     self     )						->Optional[Any]:
        # Initialize image_processing
        a	:     Any						      =    self.image_processing_class(**self.image_processor_dict     )
        # create random PIL images
        a	:     Optional[Any]						      =    prepare_image_inputs(self.image_processor_tester				,  equal_resolution=lowerCAmelCase_     )
        for image in image_inputs:
             self.assertIsInstance(lowerCAmelCase_				,  PIL.Image.Image     )

        # Test not batched input
        a	:     Any						      =    image_processing(image_inputs[0]				,  return_codebook_pixels=lowerCAmelCase_				,  return_tensors='''pt'''     )
        a      ,				a	:     int						      =    self.image_processor_tester.get_expected_codebook_image_size()
        self.assertEqual(
            encoded_images.codebook_pixel_values.shape				,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)				,  )

        # Test batched
        a	:     Dict						      =    image_processing(lowerCAmelCase_				,  return_codebook_pixels=lowerCAmelCase_				,  return_tensors='''pt'''     )
        a      ,				a	:     Any						      =    self.image_processor_tester.get_expected_codebook_image_size()
        self.assertEqual(
            encoded_images.codebook_pixel_values.shape				,  (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )				,  )
import math







def 						UpperCAmelCase							(		lowerCAmelCase_							)						->						int:
     return sum(int(lowerCAmelCase_							) for digit in str(lowerCAmelCase_							)							)







def 						UpperCAmelCase							(		lowerCAmelCase_ = 3_0							)						->						int:
     a	:     Optional[int]						      =    []
     for digit in range(2    ,   1_0_0							):
          for power in range(2    ,   1_0_0							):
               a	:     List[str]						      =    int(math.pow(lowerCAmelCase_    ,   lowerCAmelCase_							)							)
               if digit == digit_sum(lowerCAmelCase_							):
                    digit_to_powers.append(lowerCAmelCase_							)

     digit_to_powers.sort()
     return digit_to_powers[n - 1]


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