#include void simple(int r, int c) { // std::cerr << "simple\n"; long long sum = 0; int tmp; for (size_t i = 0; i < r * c; i++) { std::cin >> tmp; sum += tmp; // std::cerr << tmp << "\n"; } std::cout << sum << "\n"; } void not_so_simple(int r, int c) { // std::cerr << "not_so_simple\n"; long long sum = 0; int tmp; int min_el = 1e9; for (size_t i = 0; i < r * c; i++) { std::cin >> tmp; sum += tmp; if (i % 2 == 1 && tmp < min_el) { min_el = tmp; } } sum -= min_el; std::cout << sum << "\n"; } int main(int argc, char const *argv[]) { int r, c; std::cin >> r >> c; if (r % 2 == 1 || c % 2 == 1) { simple(r, c); } else { not_so_simple(r, c); } return 0; }