int main(){
//inputs
int n,m,sum=0,i,j;
cin>>n>>m;
int a[n][m];
for(i=0;i<n;i++){
for(j=0;j<m;j++){
cin>>a[i][j];
}
}
//calculating prefix matrix
for(j=0;j<m;j++){
for(i=1;i<m;i++){
a[i][j] += a[i-1][j];
}
}
for(i=0;i<n;i++){
for(j=1;j<m;j++){
a[i][j] += a[i][j-1];
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
cout<<a[i][j]<<" ";
}cout<<endl;
}
// finding all sum tlx = top Left X .....similarly
int tlx,tly,brx,bry;
for(tlx=0;tlx<n;tlx++){
for(tly=0;tly<m;tly++){
for(brx=tlx;brx<n;brx++){
for(bry=tly;bry<m;bry++){
sum += a[brx][bry] - a[brx][tly-1] - a[tlx-1][bry] + a[tlx-1][tly-1];
}
}
}
}
cout<<sum;
}