






"""simple docstring"""
from typing import Optional

import torch
import torch.utils.checkpoint
from torch import Tensor, nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_outputs import (
    BaseModelOutputWithNoAttention,
    BaseModelOutputWithPoolingAndNoAttention,
    ImageClassifierOutputWithNoAttention,
)
from ...modeling_utils import PreTrainedModel
from ...utils import logging
from .configuration_regnet import RegNetConfig


lowerCamelCase_					=      logging.get_logger(__name__)

# General docstring
lowerCamelCase_					=      '''RegNetConfig'''

# Base docstring
lowerCamelCase_					=      '''facebook/regnet-y-040'''
lowerCamelCase_					=      [1, 1088, 7, 7]

# Image classification docstring
lowerCamelCase_					=      '''facebook/regnet-y-040'''
lowerCamelCase_					=      '''tabby, tabby cat'''

lowerCamelCase_					=      [
    '''facebook/regnet-y-040''',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]







class 			UpperCamelCase_       (nn.Module     ):





	def __init__(      self					: List[Any]	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int = 3	,	lowerCAmelCase_					: int = 1	,	lowerCAmelCase_					: int = 1	,	lowerCAmelCase_					: Optional[str] = "relu"	,	)						->			Optional[int]:
				super().__init__()
				UpperCAmelCase_     : Union[str, Any]			     =					nn.Convad(
				    lowerCAmelCase_	,	lowerCAmelCase_	,	kernel_size=lowerCAmelCase_	,	stride=lowerCAmelCase_	,	padding=kernel_size // 2	,	groups=lowerCAmelCase_	,	bias=lowerCAmelCase_	,	)
				UpperCAmelCase_     : int			     =					nn.BatchNormad(lowerCAmelCase_						)
				UpperCAmelCase_     : Any			     =					ACTaFN[activation] if activation is not None else nn.Identity()





	def      _SCREAMING_SNAKE_CASE      (      self					: List[Any]	,	lowerCAmelCase_					: int						)						->			int:
				UpperCAmelCase_     : List[str]			     =					self.convolution(lowerCAmelCase_						)
				UpperCAmelCase_     : Union[str, Any]			     =					self.normalization(lowerCAmelCase_						)
				UpperCAmelCase_     : Dict			     =					self.activation(lowerCAmelCase_						)
				return hidden_state







class 			UpperCamelCase_       (nn.Module     ):





	def __init__(      self					: int	,	lowerCAmelCase_					: RegNetConfig						)						->			Optional[Any]:
				super().__init__()
				UpperCAmelCase_     : Optional[int]			     =					RegNetConvLayer(
				    config.num_channels	,	config.embedding_size	,	kernel_size=3	,	stride=2	,	activation=config.hidden_act						)
				UpperCAmelCase_     : Tuple			     =					config.num_channels





	def      _SCREAMING_SNAKE_CASE      (      self					: int	,	lowerCAmelCase_					: Tuple						)						->			Tuple:
				UpperCAmelCase_     : Union[str, Any]			     =					pixel_values.shape[1]
				if num_channels != self.num_channels:
							raise ValueError(
							    "Make sure that the channel dimension of the pixel values match with the one set in the configuration."						)
				UpperCAmelCase_     : Optional[Any]			     =					self.embedder(lowerCAmelCase_						)
				return hidden_state







class 			UpperCamelCase_       (nn.Module     ):





	def __init__(      self					: int	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int = 2						)						->			List[Any]:
				super().__init__()
				UpperCAmelCase_     : Optional[int]			     =					nn.Convad(lowerCAmelCase_	,	lowerCAmelCase_	,	kernel_size=1	,	stride=lowerCAmelCase_	,	bias=lowerCAmelCase_						)
				UpperCAmelCase_     : int			     =					nn.BatchNormad(lowerCAmelCase_						)





	def      _SCREAMING_SNAKE_CASE      (      self					: List[str]	,	lowerCAmelCase_					: Tensor						)						->			Tensor:
				UpperCAmelCase_     : str			     =					self.convolution(lowerCAmelCase_						)
				UpperCAmelCase_     : int			     =					self.normalization(lowerCAmelCase_						)
				return hidden_state







class 			UpperCamelCase_       (nn.Module     ):





	def __init__(      self					: List[Any]	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int						)						->			str:
				super().__init__()

				UpperCAmelCase_     : str			     =					nn.AdaptiveAvgPoolad((1, 1)						)
				UpperCAmelCase_     : int			     =					nn.Sequential(
				    nn.Convad(lowerCAmelCase_	,	lowerCAmelCase_	,	kernel_size=1						)	,	nn.ReLU()	,	nn.Convad(lowerCAmelCase_	,	lowerCAmelCase_	,	kernel_size=1						)	,	nn.Sigmoid()	,	)





	def      _SCREAMING_SNAKE_CASE      (      self					: Union[str, Any]	,	lowerCAmelCase_					: List[str]						)						->			Optional[Any]:
				# b c h w -> b c 1 1
				UpperCAmelCase_     : List[Any]			     =					self.pooler(lowerCAmelCase_						)
				UpperCAmelCase_     : Tuple			     =					self.attention(lowerCAmelCase_						)
				UpperCAmelCase_     : Dict			     =					hidden_state * attention
				return hidden_state







class 			UpperCamelCase_       (nn.Module     ):





	def __init__(      self					: Any	,	lowerCAmelCase_					: RegNetConfig	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int = 1						)						->			Optional[Any]:
				super().__init__()
				UpperCAmelCase_     : List[str]			     =					in_channels != out_channels or stride != 1
				UpperCAmelCase_     : Union[str, Any]			     =					max(1	,	out_channels // config.groups_width						)
				UpperCAmelCase_     : List[Any]			     =					(
				    RegNetShortCut(lowerCAmelCase_	,	lowerCAmelCase_	,	stride=lowerCAmelCase_						) if should_apply_shortcut else nn.Identity()
				)
				UpperCAmelCase_     : Dict			     =					nn.Sequential(
				    RegNetConvLayer(lowerCAmelCase_	,	lowerCAmelCase_	,	kernel_size=1	,	activation=config.hidden_act						)	,	RegNetConvLayer(lowerCAmelCase_	,	lowerCAmelCase_	,	stride=lowerCAmelCase_	,	groups=lowerCAmelCase_	,	activation=config.hidden_act						)	,	RegNetConvLayer(lowerCAmelCase_	,	lowerCAmelCase_	,	kernel_size=1	,	activation=lowerCAmelCase_						)	,	)
				UpperCAmelCase_     : List[Any]			     =					ACTaFN[config.hidden_act]





	def      _SCREAMING_SNAKE_CASE      (      self					: Tuple	,	lowerCAmelCase_					: Any						)						->			List[Any]:
				UpperCAmelCase_     : str			     =					hidden_state
				UpperCAmelCase_     : Union[str, Any]			     =					self.layer(lowerCAmelCase_						)
				UpperCAmelCase_     : Dict			     =					self.shortcut(lowerCAmelCase_						)
				hidden_state += residual
				UpperCAmelCase_     : int			     =					self.activation(lowerCAmelCase_						)
				return hidden_state







class 			UpperCamelCase_       (nn.Module     ):





	def __init__(      self					: Dict	,	lowerCAmelCase_					: RegNetConfig	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int = 1						)						->			Tuple:
				super().__init__()
				UpperCAmelCase_     : Optional[Any]			     =					in_channels != out_channels or stride != 1
				UpperCAmelCase_     : List[str]			     =					max(1	,	out_channels // config.groups_width						)
				UpperCAmelCase_     : Dict			     =					(
				    RegNetShortCut(lowerCAmelCase_	,	lowerCAmelCase_	,	stride=lowerCAmelCase_						) if should_apply_shortcut else nn.Identity()
				)
				UpperCAmelCase_     : Optional[Any]			     =					nn.Sequential(
				    RegNetConvLayer(lowerCAmelCase_	,	lowerCAmelCase_	,	kernel_size=1	,	activation=config.hidden_act						)	,	RegNetConvLayer(lowerCAmelCase_	,	lowerCAmelCase_	,	stride=lowerCAmelCase_	,	groups=lowerCAmelCase_	,	activation=config.hidden_act						)	,	RegNetSELayer(lowerCAmelCase_	,	reduced_channels=int(round(in_channels / 4						)						)						)	,	RegNetConvLayer(lowerCAmelCase_	,	lowerCAmelCase_	,	kernel_size=1	,	activation=lowerCAmelCase_						)	,	)
				UpperCAmelCase_     : Tuple			     =					ACTaFN[config.hidden_act]





	def      _SCREAMING_SNAKE_CASE      (      self					: Any	,	lowerCAmelCase_					: Union[str, Any]						)						->			Dict:
				UpperCAmelCase_     : Dict			     =					hidden_state
				UpperCAmelCase_     : Optional[int]			     =					self.layer(lowerCAmelCase_						)
				UpperCAmelCase_     : Any			     =					self.shortcut(lowerCAmelCase_						)
				hidden_state += residual
				UpperCAmelCase_     : str			     =					self.activation(lowerCAmelCase_						)
				return hidden_state







class 			UpperCamelCase_       (nn.Module     ):





	def __init__(      self					: List[Any]	,	lowerCAmelCase_					: RegNetConfig	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int	,	lowerCAmelCase_					: int = 2	,	lowerCAmelCase_					: int = 2	,	)						->			int:
				super().__init__()

				UpperCAmelCase_     : List[str]			     =					RegNetXLayer if config.layer_type == "x" else RegNetYLayer

				UpperCAmelCase_     : int			     =					nn.Sequential(
				    # downsampling is done in the first layer with stride of 2
				    layer(
				        lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_	,	stride=lowerCAmelCase_	,	)	,	*[layer(lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_						) for _ in range(depth - 1						)]	,	)





	def      _SCREAMING_SNAKE_CASE      (      self					: str	,	lowerCAmelCase_					: Optional[int]						)						->			Optional[int]:
				UpperCAmelCase_     : List[str]			     =					self.layers(lowerCAmelCase_						)
				return hidden_state







class 			UpperCamelCase_       (nn.Module     ):





	def __init__(      self					: List[str]	,	lowerCAmelCase_					: RegNetConfig						)						->			List[Any]:
				super().__init__()
				UpperCAmelCase_     : List[str]			     =					nn.ModuleList([]						)
				# based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
				self.stages.append(
				    RegNetStage(
				        lowerCAmelCase_	,	config.embedding_size	,	config.hidden_sizes[0]	,	stride=2 if config.downsample_in_first_stage else 1	,	depth=config.depths[0]	,	)						)
				UpperCAmelCase_     : Optional[int]			     =					zip(config.hidden_sizes	,	config.hidden_sizes[1:]						)
				for (in_channels, out_channels), depth in zip(lowerCAmelCase_	,	config.depths[1:]						):
							self.stages.append(RegNetStage(lowerCAmelCase_	,	lowerCAmelCase_	,	lowerCAmelCase_	,	depth=lowerCAmelCase_						)						)





	def      _SCREAMING_SNAKE_CASE      (      self					: Optional[Any]	,	lowerCAmelCase_					: Tensor	,	lowerCAmelCase_					: bool = False	,	lowerCAmelCase_					: bool = True						)						->			BaseModelOutputWithNoAttention:
				UpperCAmelCase_     : Optional[int]			     =					() if output_hidden_states else None

				for stage_module in self.stages:
							if output_hidden_states:
										UpperCAmelCase_     : Union[str, Any]			     =					hidden_states + (hidden_state,)

							UpperCAmelCase_     : Tuple			     =					stage_module(lowerCAmelCase_						)

				if output_hidden_states:
							UpperCAmelCase_     : List[Any]			     =					hidden_states + (hidden_state,)

				if not return_dict:
							return tuple(v for v in [hidden_state, hidden_states] if v is not None						)

				return BaseModelOutputWithNoAttention(last_hidden_state=lowerCAmelCase_	,	hidden_states=lowerCAmelCase_						)







class 			UpperCamelCase_       (__A     ):
	__magic_name__	      =				RegNetConfig
	__magic_name__	      =				'''regnet'''
	__magic_name__	      =				'''pixel_values'''
	__magic_name__	      =				True





	def      _SCREAMING_SNAKE_CASE      (      self					: List[str]	,	lowerCAmelCase_					: List[str]						)						->			Dict:
				if isinstance(lowerCAmelCase_	,	nn.Convad						):
							nn.init.kaiming_normal_(module.weight	,	mode="fan_out"	,	nonlinearity="relu"						)
				elif isinstance(lowerCAmelCase_	,	(nn.BatchNormad, nn.GroupNorm)						):
							nn.init.constant_(module.weight	,	1						)
							nn.init.constant_(module.bias	,	0						)





	def      _SCREAMING_SNAKE_CASE      (      self					: str	,	lowerCAmelCase_					: Optional[Any]	,	lowerCAmelCase_					: List[str]=False						)						->			Optional[Any]:
				if isinstance(lowerCAmelCase_	,	lowerCAmelCase_						):
							UpperCAmelCase_     : List[str]			     =					value





lowerCamelCase_					=      r'''
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it
    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
'''

lowerCamelCase_					=      r'''
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConvNextImageProcessor.__call__`] for details.

        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~file_utils.ModelOutput`] instead of a plain tuple.
'''







@add_start_docstrings(
    '''The bare RegNet model outputting raw features without any specific head on top.'''				,						__A				,						)
# Copied from transformers.models.resnet.modeling_resnet.ResNetModel with RESNET->REGNET,ResNet->RegNet
class 			UpperCamelCase_       (__A     ):





	def __init__(      self					: Union[str, Any]	,	lowerCAmelCase_					: List[str]						)						->			Optional[int]:
				super().__init__(lowerCAmelCase_						)
				UpperCAmelCase_     : Any			     =					config
				UpperCAmelCase_     : Any			     =					RegNetEmbeddings(lowerCAmelCase_						)
				UpperCAmelCase_     : Any			     =					RegNetEncoder(lowerCAmelCase_						)
				UpperCAmelCase_     : Union[str, Any]			     =					nn.AdaptiveAvgPoolad((1, 1)						)
				# Initialize weights and apply final processing
				self.post_init()





	@add_start_docstrings_to_model_forward(lowerCAmelCase_						)
	@add_code_sample_docstrings(
	    checkpoint=_CHECKPOINT_FOR_DOC	,	output_type=lowerCAmelCase_	,	config_class=_CONFIG_FOR_DOC	,	modality="vision"	,	expected_output=_EXPECTED_OUTPUT_SHAPE	,	)
	def      _SCREAMING_SNAKE_CASE      (      self					: int	,	lowerCAmelCase_					: Tensor	,	lowerCAmelCase_					: Optional[bool] = None	,	lowerCAmelCase_					: Optional[bool] = None						)						->			BaseModelOutputWithPoolingAndNoAttention:
				UpperCAmelCase_     : int			     =					(
				    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
				)
				UpperCAmelCase_     : List[str]			     =					return_dict if return_dict is not None else self.config.use_return_dict

				UpperCAmelCase_     : Union[str, Any]			     =					self.embedder(lowerCAmelCase_						)

				UpperCAmelCase_     : List[Any]			     =					self.encoder(
				    lowerCAmelCase_	,	output_hidden_states=lowerCAmelCase_	,	return_dict=lowerCAmelCase_						)

				UpperCAmelCase_     : Optional[int]			     =					encoder_outputs[0]

				UpperCAmelCase_     : Optional[int]			     =					self.pooler(lowerCAmelCase_						)

				if not return_dict:
							return (last_hidden_state, pooled_output) + encoder_outputs[1:]

				return BaseModelOutputWithPoolingAndNoAttention(
				    last_hidden_state=lowerCAmelCase_	,	pooler_output=lowerCAmelCase_	,	hidden_states=encoder_outputs.hidden_states	,	)







@add_start_docstrings(
    '''
    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    '''				,						__A				,						)
# Copied from transformers.models.resnet.modeling_resnet.ResNetForImageClassification with RESNET->REGNET,ResNet->RegNet,resnet->regnet
class 			UpperCamelCase_       (__A     ):





	def __init__(      self					: Tuple	,	lowerCAmelCase_					: str						)						->			Union[str, Any]:
				super().__init__(lowerCAmelCase_						)
				UpperCAmelCase_     : Optional[Any]			     =					config.num_labels
				UpperCAmelCase_     : Tuple			     =					RegNetModel(lowerCAmelCase_						)
				# classification head
				UpperCAmelCase_     : Optional[int]			     =					nn.Sequential(
				    nn.Flatten()	,	nn.Linear(config.hidden_sizes[-1]	,	config.num_labels						) if config.num_labels > 0 else nn.Identity()	,	)
				# initialize weights and apply final processing
				self.post_init()





	@add_start_docstrings_to_model_forward(lowerCAmelCase_						)
	@add_code_sample_docstrings(
	    checkpoint=_IMAGE_CLASS_CHECKPOINT	,	output_type=lowerCAmelCase_	,	config_class=_CONFIG_FOR_DOC	,	expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT	,	)
	def      _SCREAMING_SNAKE_CASE      (      self					: Dict	,	lowerCAmelCase_					: Optional[torch.FloatTensor] = None	,	lowerCAmelCase_					: Optional[torch.LongTensor] = None	,	lowerCAmelCase_					: Optional[bool] = None	,	lowerCAmelCase_					: Optional[bool] = None	,	)						->			ImageClassifierOutputWithNoAttention:
				UpperCAmelCase_     : Tuple			     =					return_dict if return_dict is not None else self.config.use_return_dict

				UpperCAmelCase_     : Any			     =					self.regnet(lowerCAmelCase_	,	output_hidden_states=lowerCAmelCase_	,	return_dict=lowerCAmelCase_						)

				UpperCAmelCase_     : Dict			     =					outputs.pooler_output if return_dict else outputs[1]

				UpperCAmelCase_     : Optional[int]			     =					self.classifier(lowerCAmelCase_						)

				UpperCAmelCase_     : Union[str, Any]			     =					None

				if labels is not None:
							if self.config.problem_type is None:
										if self.num_labels == 1:
													UpperCAmelCase_     : Tuple			     =					"regression"
										elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
													UpperCAmelCase_     : Dict			     =					"single_label_classification"
										else:
													UpperCAmelCase_     : List[str]			     =					"multi_label_classification"
							if self.config.problem_type == "regression":
										UpperCAmelCase_     : Union[str, Any]			     =					MSELoss()
										if self.num_labels == 1:
													UpperCAmelCase_     : Union[str, Any]			     =					loss_fct(logits.squeeze()	,	labels.squeeze()						)
										else:
													UpperCAmelCase_     : Any			     =					loss_fct(lowerCAmelCase_	,	lowerCAmelCase_						)
							elif self.config.problem_type == "single_label_classification":
										UpperCAmelCase_     : Dict			     =					CrossEntropyLoss()
										UpperCAmelCase_     : Optional[Any]			     =					loss_fct(logits.view(-1	,	self.num_labels						)	,	labels.view(-1						)						)
							elif self.config.problem_type == "multi_label_classification":
										UpperCAmelCase_     : Tuple			     =					BCEWithLogitsLoss()
										UpperCAmelCase_     : List[str]			     =					loss_fct(lowerCAmelCase_	,	lowerCAmelCase_						)

				if not return_dict:
							UpperCAmelCase_     : Optional[int]			     =					(logits,) + outputs[2:]
							return (loss,) + output if loss is not None else output

				return ImageClassifierOutputWithNoAttention(loss=lowerCAmelCase_	,	logits=lowerCAmelCase_	,	hidden_states=outputs.hidden_states						)











"""simple docstring"""
import os

def 				snake_case      (   ):
			with open(os.path.dirname(A__						) + "/grid.txt"						) as f:
						UpperCAmelCase_     : Any			     =					[]  # noqa: E741
						for _ in range(20						):
									l.append([int(A__						) for x in f.readline().split()]						)

						UpperCAmelCase_     : Any			     =					0

						# right
						for i in range(20						):
									for j in range(17						):
												UpperCAmelCase_     : Union[str, Any]			     =					l[i][j] * l[i][j + 1] * l[i][j + 2] * l[i][j + 3]
												if temp > maximum:
															UpperCAmelCase_     : Any			     =					temp

        # down
						for i in range(17						):
									for j in range(20						):
												UpperCAmelCase_     : List[Any]			     =					l[i][j] * l[i + 1][j] * l[i + 2][j] * l[i + 3][j]
												if temp > maximum:
															UpperCAmelCase_     : Tuple			     =					temp

        # diagonal 1
						for i in range(17						):
									for j in range(17						):
												UpperCAmelCase_     : str			     =					l[i][j] * l[i + 1][j + 1] * l[i + 2][j + 2] * l[i + 3][j + 3]
												if temp > maximum:
															UpperCAmelCase_     : List[str]			     =					temp

        # diagonal 2
						for i in range(17						):
									for j in range(3	,20						):
												UpperCAmelCase_     : List[Any]			     =					l[i][j] * l[i + 1][j - 1] * l[i + 2][j - 2] * l[i + 3][j - 3]
												if temp > maximum:
															UpperCAmelCase_     : List[str]			     =					temp
						return maximum


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



