lowercase__ 	=     [sum(int(c, 10) ** 2 for c in i.__str__()) for i in range(100000)]







def 						__a       (     _SCREAMING_SNAKE_CASE       )     ->int:
  a__:					Dict      							=     0
  while number:
    # Increased Speed Slightly by checking every 5 digits together.
    sum_of_digits_squared += DIGITS_SQUARED[number % 100000]
    number //= 100000

  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__ 	=     [None] * 10000000
lowercase__ 	=     True
lowercase__ 	=     False







def 						__a       (     _SCREAMING_SNAKE_CASE       )     ->bool:

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

  a__:					List[str]      							=     chain(next_number(_UpperCAmelCase       )       )
  a__:					Optional[Any]      							=     number_chain

  while number < 10000000:
    a__:					Tuple      							=     number_chain
    number *= 10

  return number_chain







def 						__a       (     _SCREAMING_SNAKE_CASE = 10000000       )     ->int:
  for i in range(1		,					_UpperCAmelCase       ):
    if CHAINS[i] is None:
      chain(i + 1       )

  return CHAINS[:number].count(_UpperCAmelCase       )


if __name__ == "__main__":
 import doctest

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



"""simple docstring"""
from typing import Any, Dict, List, Union

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
 from ..image_utils import load_image


if is_torch_available():
 import torch

 from ..models.auto.modeling_auto import MODEL_FOR_OBJECT_DETECTION_MAPPING, MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING

lowercase__ 	=     logging.get_logger(__name__)


lowercase__ 	=     Dict[str, Any]
lowercase__ 	=     List[Prediction]




@add_end_docstrings(__lowerCAmelCase    )
class        __snake_case	(					__lowerCAmelCase    ):



      def __init__(						self   ,      *lowercase   ,      **lowercase)     ->      Dict:





        '''simple docstring'''





        super().__init__(*lowercase   ,      **lowercase)

        if self.framework == "tf":
          raise ValueError(f'The {self.__class__} is only available in PyTorch.')

        requires_backends(self   ,      'vision')
        self.check_model_type(
            dict(MODEL_FOR_OBJECT_DETECTION_MAPPING.items() + MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING.items()))



      def   lowerCamelCase_       (						self   ,      **lowercase)     ->      int:





        '''simple docstring'''





        a__:					Optional[Any]      							=     {}
        if "threshold" in kwargs:
          a__:					Dict      							=     kwargs['threshold']
        return {}, {}, postprocess_kwargs



      def __call__(						self   ,      *lowercase   ,      **lowercase)     ->      Union[Predictions, List[Prediction]]:





        '''simple docstring'''





        return super().__call__(*lowercase   ,      **lowercase)



      def   lowerCamelCase_       (						self   ,      lowercase)     ->      List[Any]:





        '''simple docstring'''





        a__:					Optional[Any]      							=     load_image(lowercase)
        a__:					List[Any]      							=     torch.IntTensor([[image.height, image.width]])
        a__:					Any      							=     self.image_processor(images=[image]   ,      return_tensors='pt')
        if self.tokenizer is not None:
          a__:					Any      							=     self.tokenizer(text=inputs['words']   ,      boxes=inputs['boxes']   ,      return_tensors='pt')
        a__:					List[str]      							=     target_size
        return inputs



      def   lowerCamelCase_       (						self   ,      lowercase)     ->      int:





        '''simple docstring'''





        a__:					Any      							=     model_inputs.pop('target_size')
        a__:					Union[str, Any]      							=     self.model(**lowercase)
        a__:					List[str]      							=     outputs.__class__({'target_size': target_size, **outputs})
        if self.tokenizer is not None:
          a__:					Union[str, Any]      							=     model_inputs['bbox']
        return model_outputs



      def   lowerCamelCase_       (						self   ,      lowercase   ,      lowercase=0.9)     ->      Optional[Any]:





        '''simple docstring'''





        a__:					int      							=     model_outputs['target_size']
        if self.tokenizer is not None:
          # This is a LayoutLMForTokenClassification variant.
          # The OCR got the boxes and the model classified the words.
          a__							,   a__:					str      							=     target_size[0].tolist()

          def unnormalize(lowercase):
            return self._get_bounding_box(
                torch.Tensor(
                    [
                        (width * bbox[0] / 10_00),
                        (height * bbox[1] / 10_00),
                        (width * bbox[2] / 10_00),
                        (height * bbox[3] / 10_00),
                    ]))

          a__							,   a__:					Optional[Any]      							=     model_outputs['logits'].squeeze(0).softmax(dim=-1).max(dim=-1)
          a__:					str      							=     [self.model.config.idalabel[prediction] for prediction in classes.tolist()]
          a__:					Union[str, Any]      							=     [unnormalize(lowercase) for bbox in model_outputs['bbox'].squeeze(0)]
          a__:					Dict      							=     ['score', 'label', 'box']
          a__:					Any      							=     [dict(zip(lowercase   ,      lowercase)) for vals in zip(scores.tolist()   ,      lowercase   ,      lowercase) if vals[0] > threshold]
        else:
          # This is a regular ForObjectDetectionModel
          a__:					List[str]      							=     self.image_processor.post_process_object_detection(lowercase   ,      lowercase   ,      lowercase)
          a__:					Tuple      							=     raw_annotations[0]
          a__:					List[str]      							=     raw_annotation['scores']
          a__:					int      							=     raw_annotation['labels']
          a__:					int      							=     raw_annotation['boxes']

          a__:					List[Any]      							=     scores.tolist()
          a__:					Any      							=     [self.model.config.idalabel[label.item()] for label in labels]
          a__:					Dict      							=     [self._get_bounding_box(lowercase) for box in boxes]

          # {"scores": [...], ...} --> [{"score":x, ...}, ...]
          a__:					Optional[Any]      							=     ['score', 'label', 'box']
          a__:					List[Any]      							=     [
              dict(zip(lowercase   ,      lowercase))
              for vals in zip(raw_annotation['scores']   ,      raw_annotation['labels']   ,      raw_annotation['boxes'])
          ]

        return annotation



      def   lowerCamelCase_       (						self   ,      lowercase)     ->      Dict[str, int]:





        '''simple docstring'''





        if self.framework != "pt":
          raise ValueError('The ObjectDetectionPipeline is only available in PyTorch.')
        a__							,   a__							,   a__							,   a__:					List[Any]      							=     box.int().tolist()
        a__:					Optional[int]      							=     {
            'xmin': xmin,
            'ymin': ymin,
            'xmax': xmax,
            'ymax': ymax,
        }
        return bbox


