

import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
from ...utils import logging
from ..auto import CONFIG_MAPPING


snake_case_							=			logging.get_logger(__name__)

snake_case_							=			{
    "Salesforce/instruct-blip-flan-t5": "https://huggingface.co/Salesforce/instruct-blip-flan-t5/resolve/main/config.json",
}
class        snake_case_		(			__UpperCAmelCase):
		lowerCamelCase    :int						=     "instructblip_vision_model"







		def __init__(		self			,     __lowercase=1_4_0_8			,     __lowercase=6_1_4_4			,     __lowercase=3_9			,     __lowercase=1_6			,     __lowercase=2_2_4			,     __lowercase=1_4			,     __lowercase="gelu"			,     __lowercase=1e-6			,     __lowercase=0.0			,     __lowercase=1e-10			,     __lowercase=True			,     **__lowercase			,     )				->   str:
				super().__init__(**lowerCAmelCase_   )

				lowerCamelCase   : Optional[Any]								=hidden_size
				lowerCamelCase   : List[Any]								=intermediate_size
				lowerCamelCase   : str								=num_hidden_layers
				lowerCamelCase   : Tuple								=num_attention_heads
				lowerCamelCase   : Any								=patch_size
				lowerCamelCase   : List[str]								=image_size
				lowerCamelCase   : Optional[int]								=initializer_range
				lowerCamelCase   : List[Any]								=attention_dropout
				lowerCamelCase   : Any								=layer_norm_eps
				lowerCamelCase   : int								=hidden_act
				lowerCamelCase   : List[Any]								=qkv_bias







		@classmethod
		def 			__lowercase   (		cls			,     __lowercase			,     **__lowercase   )				->   Tuple:
				cls._set_token_in_kwargs(lowerCAmelCase_   )

				lowerCamelCase		,   lowerCamelCase   : List[Any]								=cls.get_config_dict(lowerCAmelCase_			,     **lowerCAmelCase_   )

				# get the vision config dict if we are loading from InstructBlipConfig
				if config_dict.get('''model_type'''   ) == "instructblip":
						lowerCamelCase   : str								=config_dict['''vision_config''']

				if "model_type" in config_dict and hasattr(cls			,     '''model_type'''   ) and config_dict["model_type"] != cls.model_type:
						logger.warning(
						    F"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
						    F"{cls.model_type}. This is not supported for all configurations of models and can yield errors."   )

				return cls.from_dict(lowerCAmelCase_			,     **lowerCAmelCase_   )

class        snake_case_		(			__UpperCAmelCase):
		lowerCamelCase    :List[str]						=     "instructblip_qformer"







		def __init__(		self			,     __lowercase=3_0_5_2_2			,     __lowercase=7_6_8			,     __lowercase=1_2			,     __lowercase=1_2			,     __lowercase=3_0_7_2			,     __lowercase="gelu"			,     __lowercase=0.1			,     __lowercase=0.1			,     __lowercase=5_1_2			,     __lowercase=0.0_2			,     __lowercase=1e-12			,     __lowercase=0			,     __lowercase="absolute"			,     __lowercase=2			,     __lowercase=1_4_0_8			,     **__lowercase			,     )				->   Optional[int]:
				super().__init__(pad_token_id=lowerCAmelCase_			,     **lowerCAmelCase_   )

				lowerCamelCase   : Dict								=vocab_size
				lowerCamelCase   : List[str]								=hidden_size
				lowerCamelCase   : List[str]								=num_hidden_layers
				lowerCamelCase   : Union[str, Any]								=num_attention_heads
				lowerCamelCase   : int								=hidden_act
				lowerCamelCase   : Tuple								=intermediate_size
				lowerCamelCase   : Any								=hidden_dropout_prob
				lowerCamelCase   : Dict								=attention_probs_dropout_prob
				lowerCamelCase   : int								=max_position_embeddings
				lowerCamelCase   : List[str]								=initializer_range
				lowerCamelCase   : Tuple								=layer_norm_eps
				lowerCamelCase   : str								=position_embedding_type
				lowerCamelCase   : List[str]								=cross_attention_frequency
				lowerCamelCase   : Optional[int]								=encoder_hidden_size







		@classmethod
		def 			__lowercase   (		cls			,     __lowercase			,     **__lowercase   )				->   Tuple:
				cls._set_token_in_kwargs(lowerCAmelCase_   )

				lowerCamelCase		,   lowerCamelCase   : str								=cls.get_config_dict(lowerCAmelCase_			,     **lowerCAmelCase_   )

				# get the qformer config dict if we are loading from InstructBlipConfig
				if config_dict.get('''model_type'''   ) == "instructblip":
						lowerCamelCase   : List[Any]								=config_dict['''qformer_config''']

				if "model_type" in config_dict and hasattr(cls			,     '''model_type'''   ) and config_dict["model_type"] != cls.model_type:
						logger.warning(
						    F"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
						    F"{cls.model_type}. This is not supported for all configurations of models and can yield errors."   )

				return cls.from_dict(lowerCAmelCase_			,     **lowerCAmelCase_   )

class        snake_case_		(			__UpperCAmelCase):
		lowerCamelCase    :Union[str, Any]						=     "instructblip"
		lowerCamelCase    :Any						=     True







		def __init__(		self			,     __lowercase=None			,     __lowercase=None			,     __lowercase=None			,     __lowercase=3_2			,     **__lowercase   )				->   int:
				super().__init__(**lowerCAmelCase_   )

				if vision_config is None:
						lowerCamelCase   : str								={}
						logger.info('''vision_config is None. initializing the InstructBlipVisionConfig with default values.'''   )

				if qformer_config is None:
						lowerCamelCase   : str								={}
						logger.info('''qformer_config is None. Initializing the InstructBlipQFormerConfig with default values.'''   )

				if text_config is None:
						lowerCamelCase   : Optional[int]								={}
						logger.info('''text_config is None. Initializing the text config with default values (`OPTConfig`).'''   )

				lowerCamelCase   : Tuple								=InstructBlipVisionConfig(**lowerCAmelCase_   )
				lowerCamelCase   : List[str]								=InstructBlipQFormerConfig(**lowerCAmelCase_   )
				lowerCamelCase   : Union[str, Any]								=text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
				lowerCamelCase   : str								=CONFIG_MAPPING[text_model_type](**lowerCAmelCase_   )

				lowerCamelCase   : Any								=self.text_config.tie_word_embeddings
				lowerCamelCase   : Any								=self.text_config.is_encoder_decoder

				lowerCamelCase   : Any								=num_query_tokens
				lowerCamelCase   : Any								=self.vision_config.hidden_size
				lowerCamelCase   : int								=self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
				lowerCamelCase   : List[str]								=1.0
				lowerCamelCase   : Dict								=0.0_2







		@classmethod
		def 			__lowercase   (		cls			,     __lowercase			,     __lowercase			,     __lowercase			,     **__lowercase			,     )				->   List[str]:
				return cls(
				    vision_config=vision_config.to_dict()			,     qformer_config=qformer_config.to_dict()			,     text_config=text_config.to_dict()			,     **lowerCAmelCase_			,     )







		def 			__lowercase   (		self   )				->   int:
				lowerCamelCase   : int								=copy.deepcopy(self.__dict__   )
				lowerCamelCase   : List[str]								=self.vision_config.to_dict()
				lowerCamelCase   : List[str]								=self.qformer_config.to_dict()
				lowerCamelCase   : Dict								=self.text_config.to_dict()
				lowerCamelCase   : Any								=self.__class__.model_type
				return output








from collections import defaultdict
from math import ceil, sqrt


def 					A__	(       SCREAMING_SNAKE_CASE_ = 1_0_0_0_0_0_0							,       SCREAMING_SNAKE_CASE_ = 1_0		)   ->     int:
		lowerCamelCase   : defaultdict								=defaultdict(SCREAMING_SNAKE_CASE_		)

		for outer_width in range(3							,       (t_limit // 4) + 2		):
				if outer_width * outer_width > t_limit:
						lowerCamelCase   : Any								=max(
						    ceil(sqrt(outer_width * outer_width - t_limit		)		)							,       1		)
				else:
						lowerCamelCase   : str								=1

				hole_width_lower_bound += (outer_width - hole_width_lower_bound) % 2

				for hole_width in range(SCREAMING_SNAKE_CASE_							,       outer_width - 1							,       2		):
						count[outer_width * outer_width - hole_width * hole_width] += 1

		return sum(1 for n in count.values() if 1 <= n <= 1_0		)


if __name__ == "__main__":
				print(F"""{solution() = }""")

