


'''simple docstring'''
from typing import Tuple, Union

from ...modeling_outputs import BackboneOutput
from ...modeling_utils import PreTrainedModel
from ...utils import is_timm_available, is_torch_available, requires_backends
from ...utils.backbone_utils import BackboneMixin
from .configuration_timm_backbone import TimmBackboneConfig


if is_timm_available():
 import timm


if is_torch_available():
 from torch import Tensor

class 						_lowerCamelCase					(    snake_case_    ,		snake_case_				):




 '''simple docstring'''
 __lowercase				:		str    							=						'''pixel_values'''
 __lowercase				:		Any    							=						False
 __lowercase				:		Any    							=						TimmBackboneConfig


 def __init__(      self      ,      __lowercase      ,      **__lowercase						):

  """simple docstring"""







  requires_backends(self      ,      'timm'						)
  super().__init__(__lowercase						)
  __A  :		Tuple       =			config

  if config.backbone is None:
   raise ValueError('backbone is not set in the config. Please set it to a timm model name.'						)

  if config.backbone not in timm.list_models():
   raise ValueError(F"""backbone {config.backbone} is not supported by timm."""						)

  if hasattr(__lowercase      ,      'out_features'						) and config.out_features is not None:
   raise ValueError('out_features is not supported by TimmBackbone. Please use out_indices instead.'						)

  __A  :		int       =			getattr(__lowercase      ,      'use_pretrained_backbone'      ,      __lowercase						)
  if pretrained is None:
   raise ValueError('use_pretrained_backbone is not set in the config. Please set it to True or False.'						)

  # We just take the final layer by default. This matches the default for the transformers models.
  __A  :		str       =			config.out_indices if getattr(__lowercase      ,      'out_indices'      ,      __lowercase						) is not None else (-1,)

  __A  :		Dict       =			timm.create_model(
      config.backbone      ,      pretrained=__lowercase      ,      features_only=config.features_only      ,      in_chans=config.num_channels      ,      out_indices=__lowercase      ,      **__lowercase      ,      )
  # These are used to control the output of the model when called. If output_hidden_states is True, then
  # return_layers is modified to include all layers.
  __A  :		Union[str, Any]       =			self._backbone.return_layers
  __A  :		int       =			{layer['module']: str(__lowercase						) for i, layer in enumerate(self._backbone.feature_info.info						)}
  super()._init_backbone(__lowercase						)


 @classmethod
 def  snake_case__   (      cls      ,      __lowercase      ,      *__lowercase      ,      **__lowercase						):

  """simple docstring"""







  requires_backends(cls      ,      ['vision', 'timm']						)
  from ...models.timm_backbone import TimmBackboneConfig

  __A  :		str       =			kwargs.pop('config'      ,      TimmBackboneConfig()						)

  __A  :		Union[str, Any]       =			kwargs.pop('use_timm_backbone'      ,      __lowercase						)
  if not use_timm:
   raise ValueError('use_timm_backbone must be True for timm backbones'						)

  __A  :		Union[str, Any]       =			kwargs.pop('num_channels'      ,      config.num_channels						)
  __A  :		Dict       =			kwargs.pop('features_only'      ,      config.features_only						)
  __A  :		Optional[int]       =			kwargs.pop('use_pretrained_backbone'      ,      config.use_pretrained_backbone						)
  __A  :		Any       =			kwargs.pop('out_indices'      ,      config.out_indices						)
  __A  :		Optional[int]       =			TimmBackboneConfig(
      backbone=__lowercase      ,      num_channels=__lowercase      ,      features_only=__lowercase      ,      use_pretrained_backbone=__lowercase      ,      out_indices=__lowercase      ,      )
  return super()._from_config(__lowercase      ,      **__lowercase						)


 def  snake_case__   (      self      ,      __lowercase						):

  """simple docstring"""







  pass







 def  snake_case__   (      self      ,      __lowercase      ,      __lowercase=None      ,      __lowercase=None      ,      __lowercase=None      ,      **__lowercase						):

  """simple docstring"""







  __A  :		List[str]       =			return_dict if return_dict is not None else self.config.use_return_dict
  __A  :		List[Any]       =			(
      output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
  )
  __A  :		str       =			output_attentions if output_attentions is not None else self.config.output_attentions

  if output_attentions:
   raise ValueError('Cannot output attentions for timm backbones at the moment'						)

  if output_hidden_states:
   # We modify the return layers to include all the stages of the backbone
   __A  :		Optional[Any]       =			self._all_layers
   __A  :		List[str]       =			self._backbone(__lowercase      ,      **__lowercase						)
   __A  :		Tuple       =			self._return_layers
   __A  :		int       =			tuple(hidden_states[i] for i in self.out_indices						)
  else:
   __A  :		Dict       =			self._backbone(__lowercase      ,      **__lowercase						)
   __A  :		str       =			None

  __A  :		Any       =			tuple(__lowercase						)
  __A  :		List[str]       =			tuple(__lowercase						) if hidden_states is not None else None

  if not return_dict:
   __A  :		Optional[int]       =			(feature_maps,)
   if output_hidden_states:
    __A  :		Union[str, Any]       =			output + (hidden_states,)
   return output

  return BackboneOutput(feature_maps=__lowercase      ,      hidden_states=__lowercase      ,      attentions=__lowercase						)










'''simple docstring'''
from collections import defaultdict
from math import ceil, sqrt


def 			_lowercase       (				UpperCamelCase__       :					int = 1000000,				UpperCamelCase__       :					int = 10			):
 __A  :		defaultdict       =			defaultdict(UpperCamelCase__			)

 for outer_width in range(3,				(t_limit // 4) + 2			):
  if outer_width * outer_width > t_limit:
   __A  :		Optional[int]       =			max(
       ceil(sqrt(outer_width * outer_width - t_limit			)			),				1			)
  else:
   __A  :		Optional[Any]       =			1

  hole_width_lower_bound += (outer_width - hole_width_lower_bound) % 2

  for hole_width in range(UpperCamelCase__,				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 <= 10			)


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






