local n, m = io.read("*n", "*n") local a = {} for i = 1, n do a[i] = {} for j = 1, m do a[i][j] = io.read("*n") end end local asum = {} for i = 1, m do local v = 0 for j = 1, n do v = v + a[j][i] end asum[i] = v end local scoreidx = {} local score = {} for i = 1, n do local s = 0 for j = 1, m do s = s + asum[j] * a[i][j] end score[i] = s scoreidx[i] = i end table.sort(scoreidx, function(x, y) return score[x] > score[y] end) local p1, p2 = {}, {} for i = 1, m do p1[i], p2[i] = 0, 0 end for i = 1, n do local t = i % 2 == 1 and p1 or p2 local pos = scoreidx[i] for j = 1, m do t[j] = t[j] + a[pos][j] end end local ret = 0 for i = 1, m do ret = ret + p1[i] * p1[i] - p2[i] * p2[i] end print(ret)