





from collections import UserDict
from typing import List, Union

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


if is_vision_available():
    from PIL import Image

    from ..image_utils import load_image

if is_torch_available():
    from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING

if is_tf_available():
    from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
    from ..tf_utils import stable_softmax

__lowerCamelCase	:					List[Any]			  =					logging.get_logger(__name__)



@add_end_docstrings(__snake_case      )
class  A__       (	__snake_case      ):





      def __init__(			self	,							**A_       ):
       '''simple docstring'''




       super().__init__(**A_       )

       requires_backends(self	,							"vision"       )
       self.check_model_type(
           TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
           if self.framework == "tf"
           else MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING       )





      def __call__(			self	,							A_	,							**A_       ):
       '''simple docstring'''




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





      def 	__UpperCamelCase(			self	,							**A_       ):
       '''simple docstring'''




       UpperCamelCase     : Optional[Any]	     =       {}
       if "candidate_labels" in kwargs:
        UpperCamelCase     : Optional[int]	     =       kwargs["candidate_labels"]
       if "hypothesis_template" in kwargs:
        UpperCamelCase     : int	     =       kwargs["hypothesis_template"]

       return preprocess_params, {}, {}





      def 	__UpperCamelCase(			self	,							A_	,							A_=None	,							A_="This is a photo of {}."       ):
       '''simple docstring'''




       UpperCamelCase     : Union[str, Any]	     =       load_image(A_       )
       UpperCamelCase     : int	     =       self.image_processor(images=[image]	,							return_tensors=self.framework       )
       UpperCamelCase     : Union[str, Any]	     =       candidate_labels
       UpperCamelCase     : Tuple	     =       [hypothesis_template.format(A_       ) for x in candidate_labels]
       UpperCamelCase     : Union[str, Any]	     =       self.tokenizer(A_	,							return_tensors=self.framework	,							padding=A_       )
       UpperCamelCase     : Union[str, Any]	     =       [text_inputs]
       return inputs





      def 	__UpperCamelCase(			self	,							A_       ):
       '''simple docstring'''




       UpperCamelCase     : Dict	     =       model_inputs.pop("candidate_labels"       )
       UpperCamelCase     : Optional[Any]	     =       model_inputs.pop("text_inputs"       )
       if isinstance(text_inputs[0]	,							A_       ):
        UpperCamelCase     : Optional[int]	     =       text_inputs[0]
       else:
        # Batching case.
        UpperCamelCase     : List[Any]	     =       text_inputs[0][0]

       UpperCamelCase     : int	     =       self.model(**A_	,							**A_       )

       UpperCamelCase     : str	     =       {
           "candidate_labels": candidate_labels,
           "logits": outputs.logits_per_image,
       }
       return model_outputs





      def 	__UpperCamelCase(			self	,							A_       ):
       '''simple docstring'''




       UpperCamelCase     : Any	     =       model_outputs.pop("candidate_labels"       )
       UpperCamelCase     : Optional[Any]	     =       model_outputs["logits"][0]
       if self.framework == "pt":
        UpperCamelCase     : List[str]	     =       logits.softmax(dim=-1       ).squeeze(-1       )
        UpperCamelCase     : Dict	     =       probs.tolist()
        if not isinstance(A_	,							A_       ):
         UpperCamelCase     : Dict	     =       [scores]
       elif self.framework == "tf":
        UpperCamelCase     : Any	     =       stable_softmax(A_	,							axis=-1       )
        UpperCamelCase     : List[str]	     =       probs.numpy().tolist()
       else:
        raise ValueError(F"""Unsupported framework: {self.framework}"""       )

       UpperCamelCase     : Tuple	     =       [
           {"score": score, "label": candidate_label}
           for score, candidate_label in sorted(zip(A_	,							A_       )	,							key=lambda A_       : -x[0]       )
       ]
       return result







import math



def 		A_    (					_lowerCAmelCase					)						->			list:
 UpperCamelCase     : str	     =       [True] * n
 UpperCamelCase     : Optional[int]	     =       False
 UpperCamelCase     : str	     =       False
 UpperCamelCase     : List[Any]	     =       True

 for i in range(3							,       int(n**0.5 + 1					)							,       2					):
  UpperCamelCase     : int	     =       i * 2
  while index < n:
   UpperCamelCase     : Optional[Any]	     =       False
   UpperCamelCase     : Optional[Any]	     =       index + i

 UpperCamelCase     : Optional[Any]	     =       [2]

 for i in range(3							,       _lowerCAmelCase							,       2					):
  if is_prime[i]:
   primes.append(_lowerCAmelCase					)

 return primes



def 		A_    (					_lowerCAmelCase = 9999_6666_3333					)						->			int:
 UpperCamelCase     : Tuple	     =       math.floor(math.sqrt(_lowerCAmelCase					)					) + 100
 UpperCamelCase     : Dict	     =       prime_sieve(_lowerCAmelCase					)

 UpperCamelCase     : Optional[Any]	     =       0
 UpperCamelCase     : Tuple	     =       0
 UpperCamelCase     : List[str]	     =       primes[prime_index]

 while (last_prime**2) <= limit:
  UpperCamelCase     : Dict	     =       primes[prime_index + 1]

  UpperCamelCase     : Any	     =       last_prime**2
  UpperCamelCase     : Union[str, Any]	     =       next_prime**2

  # Get numbers divisible by lps(current)
  UpperCamelCase     : Dict	     =       lower_bound + last_prime
  while upper_bound > current <= limit:
   matches_sum += current
   current += last_prime

  # Reset the upper_bound
  while (upper_bound - next_prime) > limit:
   upper_bound -= next_prime

  # Add the numbers divisible by ups(current)
  UpperCamelCase     : List[str]	     =       upper_bound - next_prime
  while current > lower_bound:
   matches_sum += current
   current -= next_prime

  # Remove the numbers divisible by both ups and lps
  UpperCamelCase     : Dict	     =       0
  while upper_bound > current <= limit:
   if current <= lower_bound:
    # Increment the current number
    current += last_prime * next_prime
    continue

   if current > limit:
    break

   # Remove twice since it was added by both ups and lps
   matches_sum -= current * 2

   # Increment the current number
   current += last_prime * next_prime

  # Setup for next pair
  UpperCamelCase     : str	     =       next_prime
  prime_index += 1

 return matches_sum


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