





from __future__ import annotations

from typing import Any



class    A__  :





      def __init__(					self			,				A_			,				A_			,				A_ = 0  ):
       '''simple docstring'''




       UpperCamelCase      ,       UpperCamelCase      :   Union[str, Any]			      =  row, column
       UpperCamelCase      :   List[Any]			      =  [[default_value for c in range(A_  )] for r in range(A_  )]





      def __str__(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   Tuple			      =  F"""Matrix consist of {self.row} rows and {self.column} columns\n"""

       # Make string identifier
       UpperCamelCase      :   int			      =  0
       for row_vector in self.array:
        for obj in row_vector:
         UpperCamelCase      :   Any			      =  max(A_			,				len(str(A_  )  )  )
       UpperCamelCase      :   int			      =  F"""%{max_element_length}s"""

       # Make string and return
       def single_line(A_  ) -> str:
        nonlocal string_format_identifier
        UpperCamelCase      :   List[Any]			      =  "["
        line += ", ".join(string_format_identifier % (obj,) for obj in row_vector  )
        line += "]"
        return line

       s += "\n".join(single_line(A_  ) for row_vector in self.array  )
       return s





      def __repr__(					self  ):
       '''simple docstring'''




       return str(self  )





      def 			__UpperCamelCase(					self			,				A_  ):
       '''simple docstring'''




       if not (isinstance(A_			,				(list, tuple)  ) and len(A_  ) == 2):
        return False
       elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column):
        return False
       else:
        return True





      def __getitem__(					self			,				A_  ):
       '''simple docstring'''




       assert self.validate_indicies(A_  )
       return self.array[loc[0]][loc[1]]





      def __setitem__(					self			,				A_			,				A_  ):
       '''simple docstring'''




       assert self.validate_indicies(A_  )
       UpperCamelCase      :   Optional[Any]			      =  value





      def __add__(					self			,				A_  ):
       '''simple docstring'''




       assert isinstance(A_			,				A_  )
       assert self.row == another.row and self.column == another.column

       # Add
       UpperCamelCase      :   Optional[int]			      =  Matrix(self.row			,				self.column  )
       for r in range(self.row  ):
        for c in range(self.column  ):
         UpperCamelCase      :   Tuple			      =  self[r, c] + another[r, c]
       return result





      def __neg__(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   Any			      =  Matrix(self.row			,				self.column  )
       for r in range(self.row  ):
        for c in range(self.column  ):
         UpperCamelCase      :   Optional[int]			      =  -self[r, c]
       return result





      def __sub__(					self			,				A_  ):
       '''simple docstring'''




       return self + (-another)





      def __mul__(					self			,				A_  ):
       '''simple docstring'''




       if isinstance(A_			,				(int, float)  ):  # Scalar multiplication
        UpperCamelCase      :   Optional[int]			      =  Matrix(self.row			,				self.column  )
        for r in range(self.row  ):
         for c in range(self.column  ):
          UpperCamelCase      :   Tuple			      =  self[r, c] * another
        return result
       elif isinstance(A_			,				A_  ):  # Matrix multiplication
        assert self.column == another.row
        UpperCamelCase      :   List[Any]			      =  Matrix(self.row			,				another.column  )
        for r in range(self.row  ):
         for c in range(another.column  ):
          for i in range(self.column  ):
           result[r, c] += self[r, i] * another[i, c]
        return result
       else:
        UpperCamelCase      :   Union[str, Any]			      =  F"""Unsupported type given for another ({type(A_  )})"""
        raise TypeError(A_  )





      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   Optional[int]			      =  Matrix(self.column			,				self.row  )
       for r in range(self.row  ):
        for c in range(self.column  ):
         UpperCamelCase      :   Optional[Any]			      =  self[r, c]
       return result





      def 			__UpperCamelCase(					self			,				A_			,				A_  ):
       '''simple docstring'''




       assert isinstance(A_			,				A_  ) and isinstance(A_			,				A_  )
       assert self.row == self.column == u.row == v.row  # u, v should be column vector
       assert u.column == v.column == 1  # u, v should be column vector

       # Calculate
       UpperCamelCase      :   Dict			      =  v.transpose()
       UpperCamelCase      :   str			      =  (v_t * self * u)[0, 0] + 1
       if numerator_factor == 0:
        return None  # It's not invertable
       return self - ((self * u) * (v_t * self) * (1.0 / numerator_factor))


# Testing
if __name__ == "__main__":



    def 						A_							(	)		->					None:
     # a^(-1)
     UpperCamelCase      :   List[str]			      =  Matrix(3				,  3				,  0	)
     for i in range(3	):
      UpperCamelCase      :   str			      =  1
     print(F"""a^(-1) is {ainv}"""	)
     # u, v
     UpperCamelCase      :   Tuple			      =  Matrix(3				,  1				,  0	)
     UpperCamelCase      ,       UpperCamelCase      ,       UpperCamelCase      :   List[str]			      =  1, 2, -3
     UpperCamelCase      :   List[Any]			      =  Matrix(3				,  1				,  0	)
     UpperCamelCase      ,       UpperCamelCase      ,       UpperCamelCase      :   int			      =  4, -2, 5
     print(F"""u is {u}"""	)
     print(F"""v is {v}"""	)
     print(F"""uv^T is {u * v.transpose()}"""	)
     # Sherman Morrison
     print(F"""(a + uv^T)^(-1) is {ainv.sherman_morrison(_lowerCAmelCase				,  _lowerCAmelCase	)}"""	)



    def 						A_							(	)		->					None:
     import doctest

     doctest.testmod()


    testa()







import os



def 						A_							(	)		->					Union[str, Any]:
 with open(os.path.dirname(_lowerCAmelCase	) + "/grid.txt"	) as f:
  UpperCamelCase      :   Optional[Any]			      =  []  # noqa: E741
  for _ in range(20	):
   l.append([int(_lowerCAmelCase	) for x in f.readline().split()]	)

  UpperCamelCase      :   str			      =  0

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

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

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

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


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