#include #include #include #include using namespace std; using u64 = long long; int hamster[1001][1001]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; u64 sum = 0; int smallest = std::numeric_limits::max(); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> hamster[i][j]; sum += hamster[i][j]; if (!((i == 0 && j == 0) || (i == n - 1 && j == m - 1))) { smallest = std::min(smallest, hamster[i][j]); } } } if (n % 2 == 1 || m % 2 == 1) { printf("%llu\n", sum); return 0; } sum -= smallest; printf("%llu\n", sum); }