#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i!=-1;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c==‘-‘) f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-‘0‘;
return x*f;
}
const int maxn=2010;
int n,m,A[maxn][maxn],ans1,ans2;
int f[maxn][maxn],left[maxn][maxn],right[maxn][maxn],up[maxn][maxn];
void solve() {
rep(i,1,n) rep(j,1,m) {
if(A[i][j]) f[i][j]=min(min(f[i-1][j],f[i][j-1]),f[i-1][j-1])+1;
else f[i][j]=0;
ans1=max(ans1,f[i][j]);
}
memset(left,0,sizeof(left));
memset(up,0,sizeof(up));
memset(right,0,sizeof(right));
rep(i,1,n) {
int p=0;
rep(j,1,m) if(!A[i][j]) up[i][j]=left[i][j]=0,p=j;
else up[i][j]=up[i-1][j]+1,left[i][j]=i==1?p+1:max(left[i-1][j],p+1);
p=m+1;
dwn(j,m,1) if(!A[i][j]) right[i][j]=m+1,p=j;
else {
right[i][j]=i==1?p-1:min(right[i-1][j],p-1);
ans2=max(ans2,up[i][j]*(right[i][j]-left[i][j]+1));
}
}
}
int main() {
n=read();m=read();
rep(i,1,n) rep(j,1,m) A[i][j]=read()^(i+j&1);
solve();
rep(i,1,n) rep(j,1,m) A[i][j]^=1;
solve();
printf("%d\n%d\n",ans1*ans1,ans2);
return 0;
}