#include <bits/stdc++.h>   using namespace std;   int A[500][500];   int B[500][500];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> A[i][j];     int mx = -1e9;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         B[i][j] = A[i][j] - (i && j ? B[i - 1][j - 1] : 0) +                   (i ? B[i - 1][j] : 0) + (j ? B[i][j - 1] : 0);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         int rx = A[i][j];         for (int k = 1; i + k < n && i - k > -1 && j + k < m && j - k > -1; ++k) {           rx += A[i - k + 1][j - k];           rx = B[i + k][j + k] + (i - k && j - k ? B[i - k - 1][j - k - 1] : 0) -                (i - k ? B[i - k - 1][j + k] : 0) -                (j - k ? B[i + k][j - k - 1] : 0) - rx;           mx = max(mx, rx);         }       }     cout << mx;     return 0;   }   