#include using namespace std; vector dx = {1, 0, 1, 1}; vector dy = {0, 1, 1, -1}; int main(){ int H, W; cin >> H >> W; vector> A(H, vector(W)); for (int i = 0; i < H; i++){ for (int j = 0; j < W; j++){ cin >> A[i][j]; } } vector>> P(H, vector>(W, vector(4))); for (int i = 0; i < H; i++){ for (int j = 0; j < W; j++){ for (int k = 0; k < 4; k++){ P[i][j][k] = i * dx[k] + j * dy[k]; } P[i][j][3] += W - 1; } } vector C = {H, W, H + W - 1, H + W - 1}; vector> sum(4); for (int i = 0; i < 4; i++){ sum[i].resize(C[i], 0); } for (int i = 0; i < H; i++){ for (int j = 0; j < W; j++){ for (int k = 0; k < 4; k++){ sum[k][P[i][j][k]] += A[i][j]; } } } int ans = 0; for (int i = 0; i < 4; i++){ for (int j = 0; j < 4; j++){ vector> sum2(C[i], vector(C[j], 0)); for (int k = 0; k < H; k++){ for (int l = 0; l < W; l++){ sum2[P[k][l][i]][P[k][l][j]] += A[k][l]; } } for (int k = 0; k < C[i]; k++){ for (int l = 0; l < C[j]; l++){ ans = max(ans, sum[i][k] + sum[j][l] - sum2[k][l]); } } } } cout << ans << endl; }