#include using namespace std; using ll = long long; constexpr char newl = '\n'; ll calcScore(const vector& v) { ll score = 0; for (ll x : v) { score += x * x; } return score; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector< vector > a(n, vector(m)); vector sum(m, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; sum[j] += a[i][j]; } } vector score(n, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { score[i] += a[i][j] * sum[j]; } } vector ids(n); iota(ids.begin(), ids.end(), 0); sort(ids.begin(), ids.end(), [&](int i1, int i2){ return score[i1] > score[i2]; }); vector cnt1(m, 0), cnt2(m, 0); for (int ii = 0; ii < n; ii++) { auto& tar = (ii % 2 == 0 ? cnt1 : cnt2); int i = ids[ii]; for (int j = 0; j < m; j++) { tar[j] += a[i][j]; } } cout << calcScore(cnt1) - calcScore(cnt2) << newl; return 0; }