#include using namespace std; typedef long long ll; typedef pair l_l; typedef pair i_i; template inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const long long INF = 1e18; //const ll mod = 1000000007; ll N, M; ll A[500][500]; vector v; ll sum[500]; ll me[500]; ll you[500]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; for(int i = 0; i < N; i++) { for(ll j = 0; j < M; j++) { cin >> A[i][j]; sum[j] += A[i][j]; } } for(int i = 0; i < N; i++) { ll tmp = 0; for(ll j = 0; j < M; j++) { tmp += sum[j] * A[i][j]; } v.push_back({tmp, i}); } sort(v.begin(), v.end(), greater()); for(int i = 0; i < N; i++) { ll idx = v[i].second; for(int j = 0; j < M; j++) { if(i % 2 == 0) me[j] += A[idx][j]; else you[j] += A[idx][j]; } } ll ans = 0; for(int i = 0; i < M; i++) ans += me[i] * me[i]; for(int i = 0; i < M; i++) ans -= you[i] * you[i]; cout << ans << endl; return 0; }