1 /**************************************************************
2 Problem: 1057
3 User: ZYBGMZL
4 Language: C++
5 Result: Accepted
6 Time:2676 ms
7 Memory:52328 kb
8 ****************************************************************/
9
10 #include<cstdio>
11 #include<cstring>
12 #include<iostream>
13 using namespace std;
14 #define dbg(x) cout<<#x<<" = "<<x<<endl
15
16 const int maxn=2005;
17
18 int n,m;
19 bool a[maxn][maxn];
20 int dP[maxn][maxn];
21 int Dp1[maxn][maxn],Dp2[maxn][maxn];
22
23 void DP1(){
24 int ans=1;
25 for(int i=0;i<n;i++)
26 for(int j=0;j<m;j++)
27 if(a[i][j]==a[i-1][j]&&a[i][j]==a[i-1][j-1]&&a[i][j]==a[i][j-1]){
28 dP[i][j]=min(dP[i-1][j],min(dP[i-1][j-1],dP[i][j-1]))+1;
29 ans=max(ans,dP[i][j]);
30 }
31 else
32 dP[i][j]=1;
33 printf("%d\n",ans*ans);
34 }
35
36 void DP2(){
37 int ans=1;
38 for(int i=0;i<n;i++)
39 for(int j=0;j<m;j++)
40 Dp1[i][j]=Dp2[i][j]=1;
41 for(int i=1;i<n;i++)
42 for(int j=0;j<m;j++)
43 if(a[i][j]==a[i-1][j])
44 Dp1[i][j]=Dp1[i-1][j]+1;
45 for(int i=n-2;i>=0;i--)
46 for(int j=0;j<m;j++)
47 if(a[i][j]==a[i+1][j])
48 Dp2[i][j]=Dp2[i+1][j]+1;
49 for(int i=0;i<n;i++){
50 int mx1=Dp1[i][0],mx2=Dp2[i][0],ml=0;
51 for(int j=0;j<m;j++){
52 ans=max(ans,(j-ml+1)*(mx1+mx2-1));
53 if(j==m-1) break;
54 if(a[i][j]!=a[i][j+1]){
55 ml=j+1;
56 mx1=Dp1[i][j+1];
57 mx2=Dp2[i][j+1];
58 }
59 else{
60 mx1=min(mx1,Dp1[i][j+1]);
61 mx2=min(mx2,Dp2[i][j+1]);
62 }
63 }
64 }
65 printf("%d\n",ans);
66 }
67
68 int main(){
69 scanf("%d%d",&n,&m);
70 for(int i=0;i<n;i++)
71 for(int j=0;j<m;j++){
72 scanf("%d",&a[i][j]);
73 a[i][j]^=(i^j)&1;
74 }
75 DP1(); DP2();
76 return 0;
77 }