#include<bits/stdc++.h>
using namespace std;
long long b[60][60];
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>b[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int k=0;
for(int s=1;s<=n;s++){
for(int d=1;d<=m;d++){
if(b[s][d]==b[i][j] and ((i-s)+(j-d))*2>k){
k=((i-s)+(j-d))*((i-s)+(j-d));
}
cout<<k<<" k ";
//cout<<b[s][d]<<" b[s][d] "<<b[i][j]<<" b[i][j] ";
//cout/*<<i<<" i "<<j<<" j "*/<<s<<" s "<<d<<" d ";
}
}
cout<<k<<" ";
k=0;
}
cout<<endl;
}
return 0;
}