This page is still under construction.

Parts of this page are still being built. What you see may change.

NEO

Time limit1sMemory limit256 MB

Summary
Find the largest submatrix with at least two rows and columns in which every submatrix meets the corner-sum inequality.
Level

Medium7 of 10

Topics
Matrix, Stack, Math
Solved
No attempts yet

Problem

Write Ai,jA_{i,j} for the element of matrix AA in row ii and column jj. A matrix AA with rr rows and ss columns is cool if both of these hold.

  • r>1r > 1 and s>1s > 1
  • A1,1+Ar,s≤A1,s+Ar,1A_{1,1} + A_{r,s} \le A_{1,s} + A_{r,1}

A matrix with at least two rows and at least two columns is extremely cool if every submatrix of it that has at least two rows and at least two columns is cool.

A submatrix is the rectangular region where a range of consecutive rows meets a range of consecutive columns.

Find an extremely cool submatrix of the given matrix and report the largest number of elements such a submatrix can have.

Input

The first line contains two integers RR and SS, the dimensions of the matrix (2≤R,S≤10002 \le R, S \le 1000).

Each of the next RR lines contains SS integers, one row of the matrix. Every element is an integer between −106-10^6 and 10610^6.

Output

Print one line with the largest number of elements an extremely cool submatrix of the given matrix has. If the matrix has no extremely cool submatrix, print 0.

Examples3

  1. Example 1

    Input
    3 3
    1 4 10
    5 2 6
    11 1 3
    
    Expected output
    9
    
  2. Example 2

    Input
    3 3
    1 3 1
    2 1 2
    1 1 1
    
    Expected output
    4
    
  3. Example 3

    Input
    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
    
    Expected output
    15