






"""simple docstring"""


import enum
import inspect
from typing import Iterable, List, Optional, Tuple, Union






class __a   (   enum.Enum				):
  __lowercase    :    List[Any]						=					'timm'
  __lowercase    :    Optional[Any]						=					'transformers'






def 				a (     UpperCamelCase_							:				Optional[Iterable[str]]     ,	UpperCamelCase_							:				Optional[Iterable[int]]     ,	UpperCamelCase_							:				Optional[Iterable[str]]		)  ->		Union[str, Any]:
 if stage_names is None:
  raise ValueError('Stage_names must be set for transformers backbones'		)

 if out_features is not None:
  if not isinstance(UpperCamelCase_     ,	(list,)		):
   raise ValueError(F"out_features must be a list {type(UpperCamelCase_		)}"		)
  if any(feat not in stage_names for feat in out_features		):
   raise ValueError(F"out_features must be a subset of stage_names: {stage_names} got {out_features}"		)

 if out_indices is not None:
  if not isinstance(UpperCamelCase_     ,	(list, tuple)		):
   raise ValueError(F"out_indices must be a list or tuple, got {type(UpperCamelCase_		)}"		)
  if any(idx >= len(UpperCamelCase_		) for idx in out_indices		):
   raise ValueError('out_indices must be valid indices for stage_names {stage_names}, got {out_indices}'		)

 if out_features is not None and out_indices is not None:
  if len(UpperCamelCase_		) != len(UpperCamelCase_		):
   raise ValueError('out_features and out_indices should have the same length if both are set'		)
  if out_features != [stage_names[idx] for idx in out_indices]:
   raise ValueError('out_features and out_indices should correspond to the same stages if both are set'		)




def 				a (     UpperCamelCase_							:				Optional[List[str]]     ,	UpperCamelCase_							:				Optional[Union[List[int], Tuple[int]]]     ,	UpperCamelCase_							:				List[str]     ,	)  ->		Union[str, Any]:
 if out_indices is None and out_features is None:
  __A	:       List[Any]       =	[len(UpperCamelCase_		) - 1]
  __A	:       Union[str, Any]       =	[stage_names[-1]]
 elif out_indices is None and out_features is not None:
  __A	:       int       =	[stage_names.index(UpperCamelCase_		) for layer in out_features]
 elif out_features is None and out_indices is not None:
  __A	:       List[Any]       =	[stage_names[idx] for idx in out_indices]
 return out_features, out_indices




def 				a (     UpperCamelCase_							:				Optional[List[str]]     ,	UpperCamelCase_							:				Optional[Union[List[int], Tuple[int]]]     ,	UpperCamelCase_							:				List[str]     ,	)  ->		Tuple[List[str], List[int]]:
 verify_out_features_out_indices(out_features=UpperCamelCase_     ,	out_indices=UpperCamelCase_     ,	stage_names=UpperCamelCase_		)
 __A    ,					__A	:       int       =	_align_output_features_output_indices(
     out_features=UpperCamelCase_     ,	out_indices=UpperCamelCase_     ,	stage_names=UpperCamelCase_		)
 # Verify that the aligned out_features and out_indices are valid
 verify_out_features_out_indices(out_features=UpperCamelCase_     ,	out_indices=UpperCamelCase_     ,	stage_names=UpperCamelCase_		)
 return output_features, output_indices






class __a   :
  __lowercase    :    Optional[BackboneType]						=					None



  def 						A_				(self  :		List[Any]				,			lowercase_  :		List[Any]   )		->							None:
   if getattr(self				,			'_backbone'				,			lowercase_   ) is None:
    raise ValueError('self._backbone must be set before calling _init_timm_backbone'   )

   # These will diagree with the defaults for the transformers models e.g. for resnet50
   # the transformer model has out_features = ['stem', 'stage1', 'stage2', 'stage3', 'stage4']
   # the timm model has out_features = ['act', 'layer1', 'layer2', 'layer3', 'layer4']
   __A	:       Dict       =	[stage['module'] for stage in self._backbone.feature_info.info]
   __A	:       Dict       =	[stage['num_chs'] for stage in self._backbone.feature_info.info]
   __A	:       Optional[Any]       =	self._backbone.feature_info.out_indices
   __A	:       Any       =	self._backbone.feature_info.module_name()

   # We verify the out indices and out features are valid
   verify_out_features_out_indices(
       out_features=lowercase_				,			out_indices=lowercase_				,			stage_names=self.stage_names   )
   __A    ,					__A	:       int       =	out_features, out_indices



  def 						A_				(self  :		str				,			lowercase_  :		Optional[Any]   )		->							None:
   __A	:       Union[str, Any]       =	getattr(lowercase_				,			'stage_names'   )
   __A	:       Dict       =	getattr(lowercase_				,			'out_features'				,			lowercase_   )
   __A	:       Union[str, Any]       =	getattr(lowercase_				,			'out_indices'				,			lowercase_   )

   __A	:       List[Any]       =	stage_names
   __A    ,					__A	:       Union[str, Any]       =	get_aligned_output_features_output_indices(
       out_features=lowercase_				,			out_indices=lowercase_				,			stage_names=lowercase_   )
   # Number of channels for each stage. This is set in the transformer backbone model init
   __A	:       Optional[int]       =	None



  def 						A_				(self  :		Union[str, Any]				,			lowercase_  :		List[str]   )		->							None:
   __A	:       Any       =	config

   __A	:       str       =	getattr(lowercase_				,			'use_timm_backbone'				,			lowercase_   )
   __A	:       Optional[Any]       =	BackboneType.TIMM if self.use_timm_backbone else BackboneType.TRANSFORMERS

   if self.backbone_type == BackboneType.TIMM:
    self._init_timm_backbone(lowercase_   )
   elif self.backbone_type == BackboneType.TRANSFORMERS:
    self._init_transformers_backbone(lowercase_   )
   else:
    raise ValueError(f"backbone_type {self.backbone_type} not supported."   )



  @property
  def 						A_				(self  :		Tuple   )		->							Optional[Any]:
   return self._out_features



  @out_features.setter
  def 						A_				(self  :		Tuple				,			lowercase_  :		List[str]   )		->							Optional[Any]:
   __A    ,					__A	:       int       =	get_aligned_output_features_output_indices(
       out_features=lowercase_				,			out_indices=lowercase_				,			stage_names=self.stage_names   )



  @property
  def 						A_				(self  :		Optional[Any]   )		->							int:
   return self._out_indices



  @out_indices.setter
  def 						A_				(self  :		Union[str, Any]				,			lowercase_  :		Union[Tuple[int], List[int]]   )		->							Union[str, Any]:
   __A    ,					__A	:       str       =	get_aligned_output_features_output_indices(
       out_features=lowercase_				,			out_indices=lowercase_				,			stage_names=self.stage_names   )



  @property
  def 						A_				(self  :		int   )		->							List[Any]:
   # the current backbones will output the number of channels for each stage
   # even if that stage is not in the out_features list.
   return {stage: self.num_features[i] for i, stage in enumerate(self.stage_names   )}



  @property
  def 						A_				(self  :		Tuple   )		->							Optional[Any]:
   return [self.out_feature_channels[name] for name in self.out_features]



  def 						A_				(self  :		List[str]				,			*lowercase_  :		int				,			**lowercase_  :		Any   )		->							List[Any]:
   __A	:       Optional[Any]       =	dict(inspect.signature(self.forward   ).parameters   )
   __A	:       Dict       =	{k: v for k, v in kwargs.items() if k in signature}
   return self(*lowercase_				,			**lowercase_   )



  def 						A_				(self  :		List[str]				,			lowercase_  :		str				,			lowercase_  :		Optional[bool] = None				,			lowercase_  :		Optional[bool] = None				,			lowercase_  :		Optional[bool] = None				,			)		->							Tuple:
   raise NotImplementedError('This method should be implemented by the derived class.'   )



  def 						A_				(self  :		int   )		->							List[Any]:
   __A	:       str       =	super().to_dict()
   __A	:       Optional[Any]       =	output.pop('_out_features'   )
   __A	:       Optional[int]       =	output.pop('_out_indices'   )
   return output






class __a   :



  @property
  def 						A_				(self  :		int   )		->							List[str]:
   return self._out_features



  @out_features.setter
  def 						A_				(self  :		Any				,			lowercase_  :		List[str]   )		->							Optional[int]:
   __A    ,					__A	:       Dict       =	get_aligned_output_features_output_indices(
       out_features=lowercase_				,			out_indices=lowercase_				,			stage_names=self.stage_names   )



  @property
  def 						A_				(self  :		List[str]   )		->							int:
   return self._out_indices



  @out_indices.setter
  def 						A_				(self  :		Tuple				,			lowercase_  :		Union[Tuple[int], List[int]]   )		->							Tuple:
   __A    ,					__A	:       Optional[int]       =	get_aligned_output_features_output_indices(
       out_features=lowercase_				,			out_indices=lowercase_				,			stage_names=self.stage_names   )



  def 						A_				(self  :		Dict   )		->							Any:
   __A	:       Union[str, Any]       =	super().to_dict()
   __A	:       int       =	output.pop('_out_features'   )
   __A	:       List[Any]       =	output.pop('_out_indices'   )
   return output













"""simple docstring"""


def 				a (     UpperCamelCase_							:				list     ,	UpperCamelCase_							:				int		)  ->		int:
 for index, item in enumerate(UpperCamelCase_		):
  if item == target:
   return index
 return -1




def 				a (     UpperCamelCase_							:				list     ,	UpperCamelCase_							:				int     ,	UpperCamelCase_							:				int     ,	UpperCamelCase_							:				int		)  ->		int:
 if not (0 <= high < len(UpperCamelCase_		) and 0 <= low < len(UpperCamelCase_		)):
  raise Exception('Invalid upper or lower bound!'		)
 if high < low:
  return -1
 if sequence[low] == target:
  return low
 if sequence[high] == target:
  return high
 return rec_linear_search(UpperCamelCase_     ,	low + 1     ,	high - 1     ,	UpperCamelCase_		)


if __name__ == "__main__":
   _UpperCamelCase   :						Any     						= input("""Enter numbers separated by comma:\n""").strip()
   _UpperCamelCase   :						Optional[Any]     						= [int(item.strip()) for item in user_input.split(""",""")]

   _UpperCamelCase   :						List[str]     						= int(input("""Enter a single number to be found in the list:\n""").strip())
   _UpperCamelCase   :						List[Any]     						= linear_search(sequence, target)
   if result != -1:
      print(f'''linear_search({sequence}, {target}) = {result}''')
   else:
      print(f'''{target} was not found in {sequence}''')





