





'''simple docstring'''




lowercase__       : List[str]         =       [sum(int(c, 10) ** 2 for c in i.__str__()) for i in range(10_00_00)]






def 			_lowerCAmelCase     (    __snake_case    :					int     )	->	int:
     __A		:					Any						=			0
     while number:
          # Increased Speed Slightly by checking every 5 digits together.
          sum_of_digits_squared += DIGITS_SQUARED[number % 10_00_00]
          number //= 10_00_00

     return sum_of_digits_squared


# There are 2 Chains made,
# One ends with 89 with the chain member 58 being the one which when declared first,
# there will be the least number of iterations for all the members to be checked.

# The other one ends with 1 and has only one element 1.

# So 58 and 1 are chosen to be declared at the starting.

# Changed dictionary to an array to quicken the solution
lowercase__       : Optional[Any]         =       [None] * 10_00_00_00
lowercase__       : Any         =       True
lowercase__       : List[Any]         =       False






def 			_lowerCAmelCase     (    __snake_case    :					int     )	->	bool:

     if CHAINS[number - 1] is not None:
          return CHAINS[number - 1]  # type: ignore

     __A		:					str						=			chain(next_number(_snake_case     )     )
     __A		:					Dict						=			number_chain

     while number < 10_00_00_00:
          __A		:					List[Any]						=			number_chain
          number *= 10

     return number_chain






def 			_lowerCAmelCase     (    __snake_case    :					int = 10_00_00_00     )	->	int:
     for i in range(1					,				_snake_case     ):
          if CHAINS[i] is None:
               chain(i + 1     )

     return CHAINS[:number].count(_snake_case     )


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  print(f"""{solution() = }""")




import unittest

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
   from PIL import Image
else:


   class 	lowerCamelCase__	:



    """simple docstring"""

    @staticmethod
    def     snake_case_      (    *__lowerCAmelCase					:					Optional[Any]			,						**__lowerCAmelCase					:					Any      )   ->	Any:
       pass


@is_pipeline_test
@require_vision
class 	lowerCamelCase__	(       unittest.TestCase):



 """simple docstring"""

 @require_torch
 def     snake_case_      (    self					:					Tuple      )   ->	Tuple:
    _A      =       pipeline(
        model='''hf-internal-testing/tiny-random-clip-zero-shot-image-classification'''			,						)
    _A      =       Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
    _A      =       image_classifier(__lowerCAmelCase			,						candidate_labels=['''a''', '''b''', '''c''']      )

    # The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
    # python and torch versions.
    self.assertIn(
        nested_simplify(__lowerCAmelCase      )			,						[
            [{'''score''': 0.333, '''label''': '''a'''}, {'''score''': 0.333, '''label''': '''b'''}, {'''score''': 0.333, '''label''': '''c'''}],
            [{'''score''': 0.333, '''label''': '''a'''}, {'''score''': 0.333, '''label''': '''c'''}, {'''score''': 0.333, '''label''': '''b'''}],
        ]			,						)

    _A      =       image_classifier([image] * 5			,						candidate_labels=['''A''', '''B''', '''C''']			,						batch_size=2      )
    self.assertEqual(
        nested_simplify(__lowerCAmelCase      )			,						[
            [
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
            ],
            [
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
            ],
            [
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
            ],
            [
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
            ],
            [
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
            ],
        ]			,						)

 @require_tf
 def     snake_case_      (    self					:					int      )   ->	Optional[int]:
    _A      =       pipeline(
        model='''hf-internal-testing/tiny-random-clip-zero-shot-image-classification'''			,						framework='''tf'''      )
    _A      =       Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
    _A      =       image_classifier(__lowerCAmelCase			,						candidate_labels=['''a''', '''b''', '''c''']      )

    self.assertEqual(
        nested_simplify(__lowerCAmelCase      )			,						[{'''score''': 0.333, '''label''': '''a'''}, {'''score''': 0.333, '''label''': '''b'''}, {'''score''': 0.333, '''label''': '''c'''}]			,						)

    _A      =       image_classifier([image] * 5			,						candidate_labels=['''A''', '''B''', '''C''']			,						batch_size=2      )
    self.assertEqual(
        nested_simplify(__lowerCAmelCase      )			,						[
            [
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
            ],
            [
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
            ],
            [
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
            ],
            [
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
            ],
            [
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
                {'''score''': 0.333, '''label''': ANY(__lowerCAmelCase      )},
            ],
        ]			,						)

 @slow
 @require_torch
 def     snake_case_      (    self					:					Optional[int]      )   ->	int:
    _A      =       pipeline(
        task='''zero-shot-image-classification'''			,						model='''openai/clip-vit-base-patch32'''			,						)
    # This is an image of 2 cats with remotes and no planes
    _A      =       Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
    _A      =       image_classifier(__lowerCAmelCase			,						candidate_labels=['''cat''', '''plane''', '''remote''']      )

    self.assertEqual(
        nested_simplify(__lowerCAmelCase      )			,						[
            {'''score''': 0.511, '''label''': '''remote'''},
            {'''score''': 0.485, '''label''': '''cat'''},
            {'''score''': 0.004, '''label''': '''plane'''},
        ]			,						)

    _A      =       image_classifier([image] * 5			,						candidate_labels=['''cat''', '''plane''', '''remote''']			,						batch_size=2      )
    self.assertEqual(
        nested_simplify(__lowerCAmelCase      )			,						[
            [
                {'''score''': 0.511, '''label''': '''remote'''},
                {'''score''': 0.485, '''label''': '''cat'''},
                {'''score''': 0.004, '''label''': '''plane'''},
            ],
        ]
        * 5			,						)

 @slow
 @require_tf
 def     snake_case_      (    self					:					Optional[int]      )   ->	Dict:
    _A      =       pipeline(
        task='''zero-shot-image-classification'''			,						model='''openai/clip-vit-base-patch32'''			,						framework='''tf'''      )
    # This is an image of 2 cats with remotes and no planes
    _A      =       Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
    _A      =       image_classifier(__lowerCAmelCase			,						candidate_labels=['''cat''', '''plane''', '''remote''']      )
    self.assertEqual(
        nested_simplify(__lowerCAmelCase      )			,						[
            {'''score''': 0.511, '''label''': '''remote'''},
            {'''score''': 0.485, '''label''': '''cat'''},
            {'''score''': 0.004, '''label''': '''plane'''},
        ]			,						)

    _A      =       image_classifier([image] * 5			,						candidate_labels=['''cat''', '''plane''', '''remote''']			,						batch_size=2      )
    self.assertEqual(
        nested_simplify(__lowerCAmelCase      )			,						[
            [
                {'''score''': 0.511, '''label''': '''remote'''},
                {'''score''': 0.485, '''label''': '''cat'''},
                {'''score''': 0.004, '''label''': '''plane'''},
            ],
        ]
        * 5			,						)



