#include #include #include #include using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); int maxRow, maxCol; cin >> maxRow >> maxCol; bool all; if(maxRow % 2 == 0 and maxCol % 2 == 0){ all = false; }else all = true; int min = 1001; long long sum = 0; int num; bool first = true; int diff = maxRow - maxCol; for(int row = 0; row < maxRow; ++row) for(int col = 0; col < maxCol; ++col){ cin >> num; if(all == true or (row - col) == diff or row == col) sum += num; else if(num < min){ if(first == true) first = false; else sum += min; min = num; }else{ sum += num; } } cout << sum << endl; }