luogu#P7958. [COCI 2014/2015 #6] NEO

[COCI 2014/2015 #6] NEO

Problem Description

A matrix AA is a "YF matrix" if and only if it satisfies:

  • r,s>1r,s>1.
  • A1,1+Ar,sA1,s+Ar,1A_{1,1}+A_{r,s}\le A_{1,s}+A_{r,1}.

Here, rr and ss are the numbers of rows and columns of matrix AA, respectively.

Also, if every submatrix of a matrix with size at least 2×22\times2 is a "YF matrix", then we call this matrix a "Sept matrix".

Given a matrix AA, you need to find the number of elements in the largest submatrix of AA that is a "Sept matrix".

Input Format

The first line contains two integers R,SR,S, which are the numbers of rows and columns of AA, respectively.

The next RR lines each contain SS integers, describing matrix AA.

Output Format

Output one line: the number of elements in the largest submatrix of AA that is a "Sept matrix".

If no such submatrix exists, output 00.

3 3
1 4 10
5 2 6
11 1 3
9
3 3
1 3 1
2 1 2
1 1 1
4
5 6
1 1 4 0 3 3
4 4 9 7 11 13
-3 -1 4 2 8 11
1 5 9 5 9 10
4 8 10 5 8 8
15

Hint

Explanation for Sample 3

The top-left and bottom-right coordinates of the largest submatrix that is a "Sept matrix" are (3,2)(3,2) and (5,6)(5,6), respectively.

Constraints

  • For 60%60\% of the testdata, R,S350R,S\le 350.
  • For 100%100\% of the testdata, 2R,S1032\le R,S\le 10^3, and Ai,j[106,106]A_{i,j}\in[-10^6,10^6].

Notes

According to the original problem settings, the full score is 140 points.

Translated from COCI 2014-2015 Contest #6 Task E NEO.

Translated by ChatGPT 5