




import copy
from typing import Dict, Optional

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING
from ..detr import DetrConfig
from ..swin import SwinConfig


snake_case_ : Optional[int]    		=       {
    "facebook/maskformer-swin-base-ade": (
        "https://huggingface.co/facebook/maskformer-swin-base-ade/blob/main/config.json"
    )
    # See all MaskFormer models at https://huggingface.co/models?filter=maskformer
}

snake_case_ : List[str]    		=       logging.get_logger(__name__)







class __snake_case			(			a		):
   UpperCAmelCase__  :    List[str]          =  '''maskformer'''
   UpperCAmelCase__  :    Optional[Any]          =  {'''hidden_size''': '''mask_feature_size'''}
   UpperCAmelCase__  :    List[str]          =  ['''resnet''', '''swin''']
   UpperCAmelCase__  :    List[str]          =  ['''detr''']







   def __init__(      self		:						Optional[int]					,						_snake_case		:						int = 256					,						_snake_case		:						int = 256					,						_snake_case		:						float = 0.1					,						_snake_case		:						bool = False					,						_snake_case		:						Optional[Dict] = None					,						_snake_case		:						Optional[Dict] = None					,						_snake_case		:						float = 0.0_2					,						_snake_case		:						float = 1.0					,						_snake_case		:						float = 1.0					,						_snake_case		:						float = 1.0					,						_snake_case		:						float = 2_0.0					,						_snake_case		:						Optional[bool] = None					,						**_snake_case		:						List[str]					,						):

        """simple docstring"""


        if backbone_config is None:
             # fall back to https://huggingface.co/microsoft/swin-base-patch4-window12-384-in22k
             UpperCAmelCase_          =							SwinConfig(
                 image_size=384					,						in_channels=3					,						patch_size=4					,						embed_dim=128					,						depths=[2, 2, 18, 2]					,						num_heads=[4, 8, 16, 32]					,						window_size=12					,						drop_path_rate=0.3					,						out_features=['''stage1''', '''stage2''', '''stage3''', '''stage4''']					,						)

        if isinstance(_snake_case					,						_snake_case):
             UpperCAmelCase_          =							backbone_config.pop('''model_type''')
             UpperCAmelCase_          =							CONFIG_MAPPING[backbone_model_type]
             UpperCAmelCase_          =							config_class.from_dict(_snake_case)

        # verify that the backbone is supported
        if backbone_config.model_type not in self.backbones_supported:
             logger.warning_once(
                 F"""Backbone {backbone_config.model_type} is not a supported model and may not be compatible with MaskFormer. """
                 F"""Supported model types: {",".join(self.backbones_supported)}""")

        if decoder_config is None:
             # fall back to https://huggingface.co/facebook/detr-resnet-50
             UpperCAmelCase_          =							DetrConfig()
        else:
             # verify that the decoder is supported
             UpperCAmelCase_          =							(
                 decoder_config.pop('''model_type''') if isinstance(_snake_case					,						_snake_case) else decoder_config.model_type
             )
             if decoder_type not in self.decoders_supported:
                  raise ValueError(
                      F"""Transformer Decoder {decoder_type} not supported, please use one of"""
                      F""" {",".join(self.decoders_supported)}""")
             if isinstance(_snake_case					,						_snake_case):
                  UpperCAmelCase_          =							CONFIG_MAPPING[decoder_type]
                  UpperCAmelCase_          =							config_class.from_dict(_snake_case)

        UpperCAmelCase_          =							backbone_config
        UpperCAmelCase_          =							decoder_config
        # main feature dimension for the model
        UpperCAmelCase_          =							fpn_feature_size
        UpperCAmelCase_          =							mask_feature_size
        # initializer
        UpperCAmelCase_          =							init_std
        UpperCAmelCase_          =							init_xavier_std
        # Hungarian matcher && loss
        UpperCAmelCase_          =							cross_entropy_weight
        UpperCAmelCase_          =							dice_weight
        UpperCAmelCase_          =							mask_weight
        UpperCAmelCase_          =							use_auxiliary_loss
        UpperCAmelCase_          =							no_object_weight
        UpperCAmelCase_          =							output_auxiliary_logits

        UpperCAmelCase_          =							self.decoder_config.encoder_attention_heads
        UpperCAmelCase_          =							self.decoder_config.num_hidden_layers
        super().__init__(**_snake_case)







   @classmethod
   def lowerCamelCase						(      cls		:						List[Any]					,						_snake_case		:						PretrainedConfig					,						_snake_case		:						PretrainedConfig					,						**_snake_case		:						Any):

        """simple docstring"""


        return cls(
            backbone_config=_snake_case					,						decoder_config=_snake_case					,						**_snake_case					,						)







   def lowerCamelCase						(      self		:						Dict):

        """simple docstring"""


        UpperCAmelCase_          =							copy.deepcopy(self.__dict__)
        UpperCAmelCase_          =							self.backbone_config.to_dict()
        UpperCAmelCase_          =							self.decoder_config.to_dict()
        UpperCAmelCase_          =							self.__class__.model_type
        return output









import os




def 			UpperCAmelCase__				(			_A      : Any							):





  '''simple docstring'''







  a__  =len(grid[0]							)
  a__  =len(_A							)

  a__  =0
  a__  =0
  a__  =0

  # Check vertically, horizontally, diagonally at the same time (only works
  # for nxn grid)
  for i in range(_A							):
    for j in range(n_rows - 3							):
      a__  =grid[j][i] * grid[j + 1][i] * grid[j + 2][i] * grid[j + 3][i]
      a__  =grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3]

      # Left-to-right diagonal (\) product
      if i < n_columns - 3:
        a__  =(
            grid[i][j]
            * grid[i + 1][j + 1]
            * grid[i + 2][j + 2]
            * grid[i + 3][j + 3]
        )

      # Right-to-left diagonal(/) product
      if i > 2:
        a__  =(
            grid[i][j]
            * grid[i - 1][j + 1]
            * grid[i - 2][j + 2]
            * grid[i - 3][j + 3]
        )

      a__  =max(
          _A	,      _A	,      _A	,      _A							)
      if max_product > largest:
        a__  =max_product

  return largest




def 			UpperCAmelCase__				(			):





  '''simple docstring'''







  a__  =[]
  with open(os.path.dirname(_A							) + '''/grid.txt'''							) as file:
    for line in file:
      grid.append(line.strip('''\n'''							).split(''' '''							)							)

  a__  =[[int(_A							) for i in grid[j]] for j in range(len(_A							)							)]

  return largest_product(_A							)


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