n,m = map(int,input().split()) A = [list(map(int,input().split())) for i in range(n)] Stonesum = [0]*m for i in range(n): for j in range(m): Stonesum[j] += A[i][j] W = [[0,i] for i in range(n)] for i in range(n): count = 0 for j in range(m): count += A[i][j]*Stonesum[j] W[i][0] = count I = [0]*m E = [0]*m W.sort(reverse=True) for i in range(n): ind = W[i][1] if i%2: for j in range(m): E[j] += A[ind][j] else: for j in range(m): I[j] += A[ind][j] calI = sum([i**2 for i in I]) calE = sum([e**2 for e in E]) print(calI-calE)