

import os
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


lowercase_       		=  logging.get_logger(__name__)

lowercase_       		=  {"vocab_file": "spiece.model"}

lowercase_       		=  {
    "vocab_file": {
        "bert_for_seq_generation": (
            "https://huggingface.co/google/bert_for_seq_generation_L-24_bbc_encoder/resolve/main/spiece.model"
        ),
    }
}

lowercase_       		=  {"bert_for_seq_generation": 512}


class  A						(							_UpperCAmelCase ):







    """simple docstring"""





    lowerCamelCase			=							VOCAB_FILES_NAMES
    lowerCamelCase			=							PRETRAINED_VOCAB_FILES_MAP
    lowerCamelCase			=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    lowerCamelCase			=							[]
    lowerCamelCase			=							['input_ids', 'attention_mask']


    def __init__(      self :       Optional[Any],lowercase_ :       List[Any],lowercase_ :       str="<s>",lowercase_ :       str="</s>",lowercase_ :       List[str]="<unk>",lowercase_ :       Any="<pad>",lowercase_ :       int="<::::>",lowercase_ :       Optional[Dict[str, Any]] = None,**lowercase_ :       Any,)->    None:





        '''simple docstring'''







        A__          =   {} if sp_model_kwargs is None else sp_model_kwargs

        # Add extra_ids to the special token list
        super().__init__(
            bos_token=lowercase_,eos_token=lowercase_,unk_token=lowercase_,pad_token=lowercase_,sep_token=lowercase_,sp_model_kwargs=self.sp_model_kwargs,**lowercase_,)

        A__          =   vocab_file

        A__          =   spm.SentencePieceProcessor(**self.sp_model_kwargs		)
        self.sp_model.Load(lowercase_		)


    @property
    def 						snake_case__     (      self :       List[Any]		)->    str:





        '''simple docstring'''







        return self.sp_model.get_piece_size()


    def 						snake_case__     (      self :       List[str]		)->    Optional[int]:





        '''simple docstring'''







        A__          =   {self.convert_ids_to_tokens(lowercase_		): i for i in range(self.vocab_size		)}
        vocab.update(self.added_tokens_encoder		)
        return vocab


    def __getstate__(      self :       Optional[Any]		)->    Optional[Any]:





        '''simple docstring'''







        A__          =   self.__dict__.copy()
        A__          =   None
        return state


    def __setstate__(      self :       Optional[int],lowercase_ :       List[str]		)->    List[Any]:





        '''simple docstring'''







        A__          =   d

        # for backward compatibility
        if not hasattr(self,'sp_model_kwargs'		):
            A__          =   {}

        A__          =   spm.SentencePieceProcessor(**self.sp_model_kwargs		)
        self.sp_model.Load(self.vocab_file		)


    def 						snake_case__     (      self :       Optional[int],lowercase_ :       str		)->    List[str]:





        '''simple docstring'''







        return self.sp_model.encode(lowercase_,out_type=lowercase_		)


    def 						snake_case__     (      self :       Union[str, Any],lowercase_ :       str		)->    Any:





        '''simple docstring'''







        return self.sp_model.piece_to_id(lowercase_		)


    def 						snake_case__     (      self :       Dict,lowercase_ :       str		)->    Union[str, Any]:





        '''simple docstring'''







        A__          =   self.sp_model.IdToPiece(lowercase_		)
        return token


    def 						snake_case__     (      self :       Tuple,lowercase_ :       Optional[Any]		)->    int:





        '''simple docstring'''







        A__          =   []
        A__          =   ''
        for token in tokens:
            # make sure that special tokens are not decoded using sentencepiece model
            if token in self.all_special_tokens:
                out_string += self.sp_model.decode(lowercase_		) + token
                A__          =   []
            else:
                current_sub_tokens.append(lowercase_		)
        out_string += self.sp_model.decode(lowercase_		)
        return out_string.strip()


    def 						snake_case__     (      self :       Union[str, Any],lowercase_ :       str,lowercase_ :       Optional[str] = None		)->    Tuple[str]:





        '''simple docstring'''







        if not os.path.isdir(lowercase_		):
            logger.error(F'Vocabulary path ({save_directory}) should be a directory'		)
            return
        A__          =   os.path.join(
            lowercase_,(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']		)

        if os.path.abspath(self.vocab_file		) != os.path.abspath(lowercase_		) and os.path.isfile(self.vocab_file		):
            copyfile(self.vocab_file,lowercase_		)
        elif not os.path.isfile(self.vocab_file		):
            with open(lowercase_,'wb'		) as fi:
                A__          =   self.sp_model.serialized_model_proto()
                fi.write(lowercase_		)

        return (out_vocab_file,)




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())
