#P7958. Maximum Sept Submatrix

    ID: 21142 Type: Default 1000ms 256MiB

Maximum Sept Submatrix

Maximum Sept Submatrix

Given a matrix (A), we define a matrix as a "YF Matrix" if and only if it satisfies the following condition (when (r,s>1)): [ A_{1,1} + A_{r,s} \le A_{1,s} + A_{r,1}, ] where (r) and (s) denote the number of rows and columns of the matrix respectively. Furthermore, a matrix is called a "Sept Matrix" if every contiguous submatrix of size at least (2\times2) is a YF Matrix. Note that any matrix with only one row or one column is trivially a Sept Matrix because no (2\times2) submatrix exists.

Given a matrix (A), your task is to find the contiguous submatrix of (A) which is a Sept Matrix and contains the maximum number of elements, and output that number of elements.

Note: A submatrix here refers to a contiguous block of rows and columns.

inputFormat

The first line contains two integers (n) and (m) representing the number of rows and columns of (A), respectively. Each of the next (n) lines contains (m) integers, describing the rows of the matrix (A).

outputFormat

Output a single integer — the maximum number of elements in a contiguous submatrix of (A) that is a Sept Matrix.

sample

3 3
1 3 4
5 6 7
8 9 10
9