#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (int)(n); ++i) //#define cerr if(false) cerr #ifdef DEBUG #define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__); #else #define show(...) 42 #endif using namespace std; using ll = long long; using pii = pair; template ostream& operator<<(ostream& os, pair a) { os << '(' << a.first << ',' << a.second << ')'; return os; } template ostream& operator<<(ostream& os, vector v) { for (auto x : v) os << x << ' '; return os; } void debug() { cerr << '\n'; } template void debug(H a, T... b) { cerr << a; if (sizeof...(b)) cerr << ", "; debug(b...); } ll a[305][305]; int main(){ int n, m; cin >> n >> m; rep(i,n)rep(j,m)cin >> a[i][j]; ll s[305]; rep(i,n)rep(j,m)s[j] += a[i][j]; vector> v; rep(i,n){ ll sum = 0; rep(j,m){ sum += 2 * a[i][j] * s[j]; } v.emplace_back(sum, i); } sort(v.rbegin(), v.rend()); ll ans = 0; ll c[305] = {}; ll d[305] = {}; rep(i,n){ rep(j,m){ if(i % 2 == 0){ c[j] += a[v[i].second][j]; }else{ d[j] += a[v[i].second][j]; } } } rep(j,m){ ans += c[j] * c[j]; ans -= d[j] * d[j]; } cout << ans << endl; }