#pragma GCC optimize("Ofast") #include #include #include using namespace std; using namespace __gnu_pbds; using ll = long long; using ull = unsigned long long; using pii = pair; using pll = pair; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; //constexpr long long MOD = 998244353LL; template inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; } template inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector> A(N, vector(M)); rep(i,N) rep(j,M) cin >> A[i][j]; vector S(M); rep(i,N) rep(j,M) S[j] += A[i][j]; vector B(N); rep(i,N) rep(j,M) B[i] += S[j]*A[i][j]; vector idx(N); iota(all(idx),0); sort(all(idx),[&](int i, int j){return B[i] > B[j];}); vector P(M),Q(M); rep(i,N) { rep(j,M) { (i&1 ? Q[j] : P[j]) += A[idx[i]][j]; } } ll ans = 0; rep(i,M) ans += P[i]*P[i] - Q[i]*Q[i]; cout << ans << ln; }