#include using namespace std; #define ll long long int main(){ int r, c; cin >> r >> c; ll res = 0; ll fourSquaresSum = 0; ll fourSquaresSum2 = 0; int LAST_SQUARES[2][2]; int FIRST_SQUARES[2][2]; for(int i = 0; i < r; i++){ for(int j = 0; j < c; j++){ ll a; cin >> a; res += a; if(i >= r - 2 && j >= c - 2){ LAST_SQUARES[r - i - 1][c - j - 1] = a; fourSquaresSum += a; } if(i < 2 && j < 2){ fourSquaresSum2 += a; FIRST_SQUARES[i][j] = a; } } } if(r % 2 != 0 || c % 2 != 0){ cout << res << endl; return 0; } res -= fourSquaresSum; // remove last 4 squares. ll max = LAST_SQUARES[0][0] + LAST_SQUARES[1][1] + std::max(LAST_SQUARES[1][0], LAST_SQUARES[0][1]); ll firstMax = res+ max; res += fourSquaresSum; res -= fourSquaresSum2; max = FIRST_SQUARES[0][0] + FIRST_SQUARES[1][1] + std::max(FIRST_SQUARES[1][0], FIRST_SQUARES[0][1]); ll secondMax = res + max; cout << std::max(secondMax, firstMax) << endl; }