1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<queue>
6 #include<deque>
7 #include<stack>
8 #include<math.h>
9 using namespace std;
10 int ma[3000][3000];
11 int a[3000][3000];
12 int b[3000][3000];
13 stack<int>stac;
14 int R[3000];
15 int L[3000];
16 int main(void)
17 {
18 int n,m;
19 int i,j;
20 scanf("%d %d",&n,&m);
21 {
22 memset(a,0,sizeof(a));
23 memset(b,0,sizeof(b));
24 for(i = 1; i <= n; i++)
25 {
26 for(j = 1; j <= m; j++)
27 {
28 scanf("%d",&ma[i][j]);
29 }
30 }
31 for(i = 1; i <= n; i++)
32 {
33 for(j = 1; j <= m; j++)
34 {
35 if((i+j)%2)
36 {
37 ma[i][j]+=1;
38 ma[i][j]%=2;
39 }
40 //printf("%d ",ma[i][j]);
41 }//printf("\n")
42 }
43 for(i = 1; i <= n; i++)
44 {
45 for(j = 1; j <= m; j++)
46 {
47 if(ma[i][j])
48 {
49 a[i][j] = a[i][j-1]+1;
50 }
51 if(!ma[i][j])
52 {
53 b[i][j] = b[i][j-1]+1;
54 }
55 }
56 }
57 int maxx = 0;
58 int maxxx = 0;
59 for(j = 1; j <= m; j++)
60 {
61 while(!stac.empty())
62 {
63 stac.pop();
64 }
65 for(i = 1; i <= n; i++)
66 {
67 if(stac.empty())
68 {
69 L[i] = 1;
70 stac.push(i);
71 }
72 else
73 {
74 while(!stac.empty())
75 {
76 int x = stac.top();
77 if(a[i][j] < a[x][j])
78 {
79 R[x] = i-1;
80 stac.pop();
81 }
82 else break;
83 }
84 if(stac.empty())
85 {
86 L[i] = 1;
87 stac.push(i);
88 }
89 else
90 {
91 L[i] = stac.top()+1;
92 stac.push(i);
93 }
94 }
95 }
96 while(!stac.empty())
97 {
98 int x= stac.top();
99 stac.pop();
100 R[x] = n;
101 }
102 for(i = 1; i <= n; i++)
103 {
104 maxx = max(maxx,(R[i]-L[i]+1)*a[i][j]);
105 maxxx = max(maxxx,min((R[i]-L[i]+1),a[i][j])*min((R[i]-L[i]+1),a[i][j]));
106 }
107 }
108 for(j = 1; j <= m; j++)
109 {
110 while(!stac.empty())
111 {
112 stac.pop();
113 }
114 for(i = 1; i <= n; i++)
115 {
116 if(stac.empty())
117 {
118 L[i] = 1;
119 stac.push(i);
120 }
121 else
122 {
123 while(!stac.empty())
124 {
125 int x = stac.top();
126 if(b[i][j] <= b[x][j])
127 {
128 R[x] = i-1;
129 stac.pop();
130 }
131 else break;
132 }
133 if(stac.empty())
134 {
135 L[i] = 1;
136 stac.push(i);
137 }
138 else
139 {
140 L[i] = stac.top()+1;
141 stac.push(i);
142 }
143 }
144 }
145 while(!stac.empty())
146 {
147 int x= stac.top();
148 stac.pop();
149 R[x] = n;
150 }
151 for(i = 1; i <= n; i++)
152 {
153 maxx = max(maxx,(R[i]-L[i]+1)*b[i][j]);
154 maxxx = max(maxxx,min((R[i]-L[i]+1),b[i][j])*min((R[i]-L[i]+1),b[i][j]));
155 }
156 }
157 printf("%d\n",maxxx);
158 printf("%d\n",maxx);
159 }
160 return 0;
161 }