

from typing import Optional, Tuple

import flax.linen as nn
import jax
import jax.numpy as jnp
from configuration_hybrid_clip import HybridCLIPConfig
from flax.core.frozen_dict import FrozenDict

from transformers import FLAX_MODEL_MAPPING, FlaxCLIPVisionModel
from transformers.modeling_flax_utils import FlaxPreTrainedModel
from transformers.models.clip.modeling_flax_clip import FlaxCLIPOutput
from transformers.utils import logging


A__										=      logging.get_logger(__name__)







class  UpperCamelCase_      (	nn.Module      ):


  """simple docstring"""
  SCREAMING_SNAKE_CASE__					:			HybridCLIPConfig
  SCREAMING_SNAKE_CASE__					:			jnp.dtype					    =   jnp.floataa



  def   _UpperCamelCase     (						self     :					Optional[Any]						)       ->			Tuple:
      SCREAMING_SNAKE_CASE__         =    self.config.text_config
      SCREAMING_SNAKE_CASE__         =    self.config.vision_config

      SCREAMING_SNAKE_CASE__         =    self.config.projection_dim
      SCREAMING_SNAKE_CASE__         =    text_config.hidden_size
      SCREAMING_SNAKE_CASE__         =    vision_config.hidden_size

      SCREAMING_SNAKE_CASE__         =    FLAX_MODEL_MAPPING[self.config.text_config.__class__].module_class
      SCREAMING_SNAKE_CASE__         =    FLAX_MODEL_MAPPING.get(self.config.vision_config.__class__  ,	A_						).module_class

      SCREAMING_SNAKE_CASE__         =    text_module(A_  ,	dtype=self.dtype						)
      SCREAMING_SNAKE_CASE__         =    vision_module(A_  ,	dtype=self.dtype						)

      SCREAMING_SNAKE_CASE__         =    nn.Dense(
          self.projection_dim  ,	dtype=self.dtype  ,	kernel_init=jax.nn.initializers.normal(0.02						)  ,	use_bias=A_  ,	)
      SCREAMING_SNAKE_CASE__         =    nn.Dense(
          self.projection_dim  ,	dtype=self.dtype  ,	kernel_init=jax.nn.initializers.normal(0.02						)  ,	use_bias=A_  ,	)
      SCREAMING_SNAKE_CASE__         =    self.param("logit_scale"  ,	jax.nn.initializers.ones  ,	[]						)







  def __call__(						self     :					Union[str, Any]  ,	A_     :					str=None  ,	A_     :					str=None  ,	A_     :					List[Any]=None  ,	A_     :					Tuple=None  ,	A_     :					Dict=None  ,	A_     :					bool = True  ,	A_     :					Dict=None  ,	A_     :					Any=None  ,	A_     :					Optional[Any]=None  ,	)       ->			Any:
      SCREAMING_SNAKE_CASE__         =    return_dict if return_dict is not None else self.config.return_dict

      SCREAMING_SNAKE_CASE__         =    self.vision_model(
          pixel_values=A_  ,	deterministic=A_  ,	output_attentions=A_  ,	output_hidden_states=A_  ,	return_dict=A_  ,	)

      SCREAMING_SNAKE_CASE__         =    self.text_model(
          input_ids=A_  ,	attention_mask=A_  ,	token_type_ids=A_  ,	position_ids=A_  ,	deterministic=A_  ,	output_attentions=A_  ,	output_hidden_states=A_  ,	return_dict=A_  ,	)

      SCREAMING_SNAKE_CASE__         =    vision_outputs[1]
      SCREAMING_SNAKE_CASE__         =    self.visual_projection(A_						)

      SCREAMING_SNAKE_CASE__         =    text_outputs[1]
      SCREAMING_SNAKE_CASE__         =    self.text_projection(A_						)

      # normalized features
      SCREAMING_SNAKE_CASE__         =    image_embeds / jnp.linalg.norm(A_  ,	axis=-1  ,	keepdims=A_						)
      SCREAMING_SNAKE_CASE__         =    text_embeds / jnp.linalg.norm(A_  ,	axis=-1  ,	keepdims=A_						)

      # cosine similarity as logits
      SCREAMING_SNAKE_CASE__         =    jnp.exp(self.logit_scale						)
      SCREAMING_SNAKE_CASE__         =    jnp.matmul(A_  ,	image_embeds.T						) * logit_scale
      SCREAMING_SNAKE_CASE__         =    logits_per_text.T

      if not return_dict:
          return (logits_per_image, logits_per_text, text_embeds, image_embeds, text_outputs, vision_outputs)

      return FlaxCLIPOutput(
          logits_per_image=A_  ,	logits_per_text=A_  ,	text_embeds=A_  ,	image_embeds=A_  ,	text_model_output=A_  ,	vision_model_output=A_  ,	)







class  UpperCamelCase_      (	_snake_case      ):


  """simple docstring"""
  SCREAMING_SNAKE_CASE__					:			Dict					    =   HybridCLIPConfig
  SCREAMING_SNAKE_CASE__					:			Dict					    =   FlaxHybridCLIPModule



  def __init__(						self     :					List[str]  ,	A_     :					HybridCLIPConfig  ,	A_     :					Optional[Tuple] = None  ,	A_     :					int = 0  ,	A_     :					jnp.dtype = jnp.floataa  ,	**A_     :					Union[str, Any]  ,	)       ->			Optional[int]:
      if input_shape is None:
          SCREAMING_SNAKE_CASE__         =    ((1, 1), (1, config.vision_config.image_size, config.vision_config.image_size, 3))

      SCREAMING_SNAKE_CASE__         =    self.module_class(config=A_  ,	dtype=A_  ,	**A_						)
      super().__init__(A_  ,	A_  ,	input_shape=A_  ,	seed=A_  ,	dtype=A_						)



  def   _UpperCamelCase     (						self     :					List[str]  ,	A_     :					jax.random.PRNGKey  ,	A_     :					Tuple  ,	A_     :					FrozenDict = None						)       ->			FrozenDict:
      # init input tensor
      SCREAMING_SNAKE_CASE__         =    jnp.zeros(input_shape[0]  ,	dtype="i4"						)
      SCREAMING_SNAKE_CASE__         =    jnp.broadcast_to(jnp.arange(jnp.atleast_ad(A_						).shape[-1]						)  ,	input_shape[0]						)
      SCREAMING_SNAKE_CASE__         =    jnp.ones_like(A_						)
      SCREAMING_SNAKE_CASE__         =    jnp.ones_like(A_						)

      SCREAMING_SNAKE_CASE__         =    jax.random.normal(A_  ,	input_shape[1]						)

      SCREAMING_SNAKE_CASE__  ,		SCREAMING_SNAKE_CASE__         =    jax.random.split(A_						)
      SCREAMING_SNAKE_CASE__         =    {"params": params_rng, "dropout": dropout_rng}

      return self.module.init(A_  ,	A_  ,	A_  ,	A_  ,	A_  ,	A_						)["params"]



  def __call__(						self     :					Optional[int]  ,	A_     :					int  ,	A_     :					Tuple  ,	A_     :					Dict=None  ,	A_     :					Optional[Any]=None  ,	A_     :					Optional[Any]=None  ,	A_     :					dict = None  ,	A_     :					jax.random.PRNGKey = None  ,	A_     :					bool = False  ,	A_     :					Optional[bool] = None  ,	A_     :					Optional[bool] = None  ,	A_     :					Optional[bool] = None  ,	)       ->			List[Any]:
      SCREAMING_SNAKE_CASE__         =    output_attentions if output_attentions is not None else self.config.output_attentions
      SCREAMING_SNAKE_CASE__         =    (
          output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
      )
      SCREAMING_SNAKE_CASE__         =    return_dict if return_dict is not None else self.config.return_dict

      if position_ids is None:
          SCREAMING_SNAKE_CASE__         =    jnp.broadcast_to(jnp.arange(jnp.atleast_ad(A_						).shape[-1]						)  ,	input_ids.shape						)

      if token_type_ids is None:
          SCREAMING_SNAKE_CASE__         =    jnp.zeros_like(A_						)

      if attention_mask is None:
          SCREAMING_SNAKE_CASE__         =    jnp.ones_like(A_						)

      # Handle any PRNG if needed
      SCREAMING_SNAKE_CASE__         =    {}
      if dropout_rng is not None:
          SCREAMING_SNAKE_CASE__         =    dropout_rng

      return self.module.apply(
          {"params": params or self.params}  ,	jnp.array(A_  ,	dtype="i4"						)  ,	jnp.array(A_  ,	dtype=jnp.floataa						)  ,	jnp.array(A_  ,	dtype="i4"						)  ,	jnp.array(A_  ,	dtype="i4"						)  ,	jnp.array(A_  ,	dtype="i4"						)  ,	not train  ,	A_  ,	A_  ,	A_  ,	rngs=A_  ,	)



  def   _UpperCamelCase     (						self     :					str  ,	A_     :					int  ,	A_     :					Tuple=None  ,	A_     :					Optional[Any]=None  ,	A_     :					int=None  ,	A_     :					dict = None  ,	A_     :					jax.random.PRNGKey = None  ,	A_     :					Any=False  ,	)       ->			List[str]:
      if position_ids is None:
          SCREAMING_SNAKE_CASE__         =    jnp.broadcast_to(jnp.arange(jnp.atleast_ad(A_						).shape[-1]						)  ,	input_ids.shape						)

      if token_type_ids is None:
          SCREAMING_SNAKE_CASE__         =    jnp.zeros_like(A_						)

      if attention_mask is None:
          SCREAMING_SNAKE_CASE__         =    jnp.ones_like(A_						)

      # Handle any PRNG if needed
      SCREAMING_SNAKE_CASE__         =    {}
      if dropout_rng is not None:
          SCREAMING_SNAKE_CASE__         =    dropout_rng

      def _get_features(A_     :					str  ,	A_     :					Dict  ,	A_     :					Union[str, Any]  ,	A_     :					List[Any]  ,	A_     :					str  ,	A_     :					Tuple						):
          SCREAMING_SNAKE_CASE__         =    module.text_model(
              input_ids=A_  ,	attention_mask=A_  ,	position_ids=A_  ,	token_type_ids=A_  ,	deterministic=A_  ,	)
          SCREAMING_SNAKE_CASE__         =    text_outputs[1]
          SCREAMING_SNAKE_CASE__         =    module.text_projection(A_						)
          return text_features

      return self.module.apply(
          {"params": params or self.params}  ,	jnp.array(A_  ,	dtype="i4"						)  ,	jnp.array(A_  ,	dtype="i4"						)  ,	jnp.array(A_  ,	dtype="i4"						)  ,	jnp.array(A_  ,	dtype="i4"						)  ,	not train  ,	method=_get_features  ,	rngs=A_  ,	)



  def   _UpperCamelCase     (						self     :					Optional[int]  ,	A_     :					str  ,	A_     :					dict = None  ,	A_     :					jax.random.PRNGKey = None  ,	A_     :					Dict=False						)       ->			Dict:
      SCREAMING_SNAKE_CASE__         =    {}
      if dropout_rng is not None:
          SCREAMING_SNAKE_CASE__         =    dropout_rng

      def _get_features(A_     :					Tuple  ,	A_     :					int  ,	A_     :					str						):
          SCREAMING_SNAKE_CASE__         =    module.vision_model(pixel_values=A_  ,	deterministic=A_						)
          SCREAMING_SNAKE_CASE__         =    vision_outputs[1]  # pooled_output
          SCREAMING_SNAKE_CASE__         =    module.visual_projection(A_						)
          return image_features

      return self.module.apply(
          {"params": params or self.params}  ,	jnp.array(A_  ,	dtype=jnp.floataa						)  ,	not train  ,	method=_get_features  ,	rngs=A_  ,	)







  @classmethod
  def   _UpperCamelCase     (						cls     :					Tuple  ,	A_     :					str = None  ,	A_     :					str = None  ,	*A_     :					Union[str, Any]  ,	**A_     :					Optional[Any]  ,	)       ->			FlaxPreTrainedModel:
      SCREAMING_SNAKE_CASE__         =    {
          argument[len("text_"						) :]: value for argument, value in kwargs.items() if argument.startswith("text_"						)
      }

      SCREAMING_SNAKE_CASE__         =    {
          argument[len("vision_"						) :]: value for argument, value in kwargs.items() if argument.startswith("vision_"						)
      }

      # remove text, vision kwargs from kwargs
      for key in kwargs_text.keys():
          del kwargs["text_" + key]
      for key in kwargs_vision.keys():
          del kwargs["vision_" + key]

      # Load and initialize the text and vision model
      SCREAMING_SNAKE_CASE__         =    kwargs_text.pop("model"  ,	A_						)
      if text_model is None:
          assert (
              text_model_name_or_path is not None
          ), "If `model` is not defined as an argument, a `text_model_name_or_path` has to be defined"
          from transformers import FlaxAutoModel

          if "config" not in kwargs_text:
              from transformers import AutoConfig

              SCREAMING_SNAKE_CASE__         =    AutoConfig.from_pretrained(A_						)
              SCREAMING_SNAKE_CASE__         =    text_config

          SCREAMING_SNAKE_CASE__         =    FlaxAutoModel.from_pretrained(A_  ,	*A_  ,	**A_						)

      SCREAMING_SNAKE_CASE__         =    kwargs_vision.pop("model"  ,	A_						)
      if vision_model is None:
          assert (
              vision_model_name_or_path is not None
          ), "If `model` is not defined as an argument, a `vision_model_name_or_path` has to be defined"
          from transformers import FlaxAutoModel

          if "config" not in kwargs_vision:
              from transformers import AutoConfig

              SCREAMING_SNAKE_CASE__         =    AutoConfig.from_pretrained(A_						)
              SCREAMING_SNAKE_CASE__         =    vision_config

          SCREAMING_SNAKE_CASE__         =    FlaxAutoModel.from_pretrained(A_  ,	*A_  ,	**A_						)

      # instantiate config with corresponding kwargs
      SCREAMING_SNAKE_CASE__         =    kwargs.pop("dtype"  ,	jnp.floataa						)
      SCREAMING_SNAKE_CASE__         =    HybridCLIPConfig.from_text_vision_configs(text_model.config  ,	vision_model.config  ,	**A_						)

      # init model
      SCREAMING_SNAKE_CASE__         =    cls(A_  ,	*A_  ,	dtype=A_  ,	**A_						)

      if vision_config.model_type == "clip":
          SCREAMING_SNAKE_CASE__         =    vision_model.params["vision_model"]
          SCREAMING_SNAKE_CASE__         =    vision_model.params["visual_projection"]["kernel"]
      else:
          SCREAMING_SNAKE_CASE__         =    vision_model.params

      SCREAMING_SNAKE_CASE__         =    text_model.params

      return model





A__										=      10**8





def 				__a							(       __A						):
    if n % 10 == 0:
        return False
    SCREAMING_SNAKE_CASE__         =    str(__A						)
    return s == s[::-1]





def 				__a							(       ):
    SCREAMING_SNAKE_CASE__         =    set()
    SCREAMING_SNAKE_CASE__         =    1
    SCREAMING_SNAKE_CASE__         =    5
    while sum_squares < LIMIT:
        SCREAMING_SNAKE_CASE__         =    first_square + 1
        while sum_squares < LIMIT:
            if is_palindrome(__A						):
                answer.add(__A						)
            last_square += 1
            sum_squares += last_square**2
        first_square += 1
        SCREAMING_SNAKE_CASE__         =    first_square**2 + (first_square + 1) ** 2

    return sum(__A						)


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


