import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N, M = map(int, input().split()) A = tuple(tuple(map(int, input().split())) for _ in range(N)) S = [0] * M for i in range(N): for j in range(M): S[j] += A[i][j] tmp = [] for i in range(N): score = sum(S[j]*A[i][j] for j in range(M)) tmp.append((score, i)) tmp.sort(reverse=True) X = [0]*M Y = [0]*M for i, (_, idx) in enumerate(tmp): if i % 2 == 0: for j, c in enumerate(A[idx]): X[j] += c else: for j, c in enumerate(A[idx]): Y[j] += c ans = sum(x*x for x in X) - sum(y*y for y in Y) print(ans)