import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); Box[] boxes = new Box[n]; int[] sums = new int[m]; for (int i = 0; i < n; i++) { int[] values = new int[m]; for (int j = 0; j < m; j++) { values[j] = sc.nextInt(); sums[j] += values[j]; } boxes[i] = new Box(values); } Box.values = sums; for (Box b : boxes) { b.calc(); } Arrays.sort(boxes); long[] ev = new long[m]; long[] od = new long[m]; for (int i = 0; i < n; i++) { if (i % 2 == 0) { boxes[i].add(ev); } else { boxes[i].add(od); } } long ans = 0; for (int i = 0; i < m; i++) { ans -= ev[i] * ev[i] - od[i] * od[i]; } System.out.println(ans); } static class Box implements Comparable { static int[] values; int[] counts; long score; public Box(int[] counts) { this.counts = counts; } public void calc() { for (int i = 0; i < counts.length; i++) { score += values[i] * counts[i]; } } public int compareTo(Box another) { if (score == another.score) { return 0; } else if (score < another.score) { return -1; } else { return 1; } } public void add(long[] arr) { for (int i = 0; i < arr.length; i++) { arr[i] += counts[i]; } } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }