#include "bits/stdc++.h" using namespace std; #define int long long #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i) #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i) #define ALL(a) a.begin(), a.end() #define IN(a, x, b) (a <= x && x < b) templateinline void out(T t){cout << t << "\n";} templateinline void out(T t,Ts... ts){cout << t << " ";out(ts...);} templateinline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;} templateinline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;} constexpr int INF = 1e18; #define endl '\n' #define IOS() ios_base::sync_with_stdio(0);cin.tie(0) void solve(){ int N,M; cin >> N >> M; vector>c(N,vector(M)); REP(i,N){ REP(j,M){ cin >> c[i][j]; } } vectora(M),b(M); vectorused(N); REP(i,N){ int ma = -INF,idx = -1; REP(j,N){ if(used[j])continue; auto next = a; if(i % 2)next = b; REP(k,M){ next[k] += c[j][k]; } int sum = 0; REP(k,M){ sum += next[k] * next[k]; } if(CHMAX(ma,sum)){ idx = j; } } if(i % 2){ REP(j,M)b[j] += c[idx][j]; }else{ REP(j,M)a[j] += c[idx][j]; } used[idx] = 1; } int ans = 0; REP(i,M)ans += a[i] * a[i] - b[i] * b[i]; out(ans); } signed main(){ IOS(); int Q = 1; //cin >> Q; while(Q--)solve(); }