1 #include <iostream>
2 #include <cstring>
3 #include <string>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <cmath>
7 #include <algorithm>
8 #include <queue>
9 #include <stack>
10 #include <map>
11 #include <set>
12 #include <list>
13 #include <vector>
14 #include <ctime>
15 #include <functional>
16 #define pritnf printf
17 #define scafn scanf
18 #define sacnf scanf
19 #define For(i,j,k) for(int i=(j);i<=(k);(i)++)
20 #define Clear(a) memset(a,0,sizeof(a))
21 using namespace std;
22 typedef unsigned int Uint;
23 const int INF=0x3fffffff;
24 ///==============struct declaration==============
25
26 ///==============var declaration=================
27 const int MAXN=2050;
28 int row,col;
29 int pic[MAXN][MAXN];
30 int h[MAXN],l[MAXN],r[MAXN];
31 ///==============function declaration============
32 int FindSquare(int val);
33 int FindRectangle(int val);
34 ///==============main code=======================
35 int main()
36 {
37 #define FILE__
38 #ifdef FILE__
39 freopen("input","r",stdin);
40 freopen("output","w",stdout);
41 #endif
42 scanf("%d%d",&row,&col);
43 for(int i=1;i<=row;i++)
44 for(int j=1;j<=col;j++){
45 scanf("%d",&pic[i][j]);
46 if ((i+j)&1) pic[i][j]=!pic[i][j];
47 }
48 printf("%d\n",max(FindSquare(1),FindSquare(0)));
49 printf("%d\n",max(FindRectangle(1),FindRectangle(0)));
50 return 0;
51 }
52 ///================fuction code====================
53 int FindSquare(int val){
54 memset(h,0,sizeof(h));int ans=0;
55 for(int i=1;i<=row;i++){
56 for(int j=1;j<=col;j++)
57 if (pic[i][j]==val) h[j]=h[j]+1;
58 else h[j]=0;
59 for(int j=1;j<=col;j++){
60 l[j]=j;
61 while (l[j]>1&&h[l[j]-1]>=h[j])
62 l[j]=l[l[j]-1];
63 }
64 for(int j=col;j>=1;j--){
65 r[j]=j;
66 while (r[j]<col&&h[r[j]+1]>=h[j])
67 r[j]=r[r[j]+1];
68 }
69 for(int j=1;j<=col;j++){
70 int w=r[j]-l[j]+1;
71 w=min(w,h[j]);
72 ans=max(ans,w*w);
73 }
74 }
75 return ans;
76 }
77 int FindRectangle(int val){
78 memset(h,0,sizeof(h));int ans=0;
79 for(int i=1;i<=row;i++){
80 for(int j=1;j<=col;j++)
81 if (pic[i][j]==val) h[j]=h[j]+1;
82 else h[j]=0;
83 for(int j=1;j<=col;j++){
84 l[j]=j;
85 while (l[j]>1&&h[l[j]-1]>=h[j])
86 l[j]=l[l[j]-1];
87 }
88 for(int j=col;j>=1;j--){
89 r[j]=j;
90 while (r[j]<col&&h[r[j]+1]>=h[j])
91 r[j]=r[r[j]+1];
92 }
93 for(int i=1;i<=col;i++){
94 int w=r[i]-l[i]+1;
95 ans=max(ans,w*h[i]);
96 }
97 }
98 return ans;
99 }