#include #define FASTIO using namespace std; using ll = long long; using Vi = vector; using Vl = vector; using Pii = pair; using Pll = pair; constexpr int I_INF = numeric_limits::max(); constexpr ll L_INF = numeric_limits::max(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void solve() { ll N, M; cin >> N >> M; vector A(N, Vl(M)); for (ll i = 0; i < N; i++) { for (ll j = 0; j < M; j++) { cin >> A[i][j]; } } Vl ds(M); for (ll j = 0; j < M; j++) { for (ll i = 0; i < N; i++) { ds[j] += A[i][j]; } } Vl es(N); for (ll i = 0; i < N; i++) { for (ll j = 0; j < M; j++) { es[i] += A[i][j] * ds[j]; } } sort(es.begin(), es.end(), greater()); ll ans = 0; for (ll i = 0; i < N; i++) { if (i & 1) { ans -= es[i]; } else { ans += es[i]; } } cout << ans << "\n"; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int main() { #ifdef FASTIO cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); #endif #ifdef FILEINPUT ifstream ifs("./in_out/input.txt"); cin.rdbuf(ifs.rdbuf()); #endif #ifdef FILEOUTPUT ofstream ofs("./in_out/output.txt"); cout.rdbuf(ofs.rdbuf()); #endif solve(); cout << flush; return 0; }