import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] x = new int[n][d];
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		}
		int ans = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] x = new int[n][d];
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		}
		int ans = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] x = new int[n][d];
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		}
		int ans = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] x = new int[n][d];
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		}
		int ans = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int d = Integer.parseInt(sc.next()); d Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[][] x = new int[n][d]; x new int[n][d] n d for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		} int i = 0; int i = 0; i 0 i < x.length i x.length x x.length i++ i++ i {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		} {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		} for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			} int j = 0; int j = 0; j 0 j < x[i].length j x[i].length x[i] x i x[i].length j++ j++ j {
				x[i][j] = Integer.parseInt(sc.next());
			} {
				x[i][j] = Integer.parseInt(sc.next());
			} x[i][j] = Integer.parseInt(sc.next()) x[i][j] x[i] x i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int ans = 0; ans 0 for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		} int i = 0; int i = 0; i 0 i < x.length - 1 i x.length - 1 x.length x x.length 1 i++ i++ i {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		} {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		} for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < x.length j x.length x x.length j++ j++ j {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			} {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			} int tmp = 0; tmp 0 double distance = 0; distance 0 for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				} int j2 = 0; int j2 = 0; j2 0 j2 < x[i].length j2 x[i].length x[i] x i x[i].length j2++ j2++ j2 {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				} {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				} tmp += Math.pow(x[i][j2] - x[j][j2], 2) tmp Math.pow(x[i][j2] - x[j][j2], 2) Math.pow Math x[i][j2] - x[j][j2] x[i][j2] x[i] x i j2 x[j][j2] x[j] x j j2 2 distance = Math.sqrt(tmp) distance Math.sqrt(tmp) Math.sqrt Math tmp if ((distance - (int) distance) == 0.0) {
					ans++;
				} (distance - (int) distance) == 0.0 (distance - (int) distance) distance (int) distance 0.0 {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] x = new int[n][d];
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		}
		int ans = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}
} public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] x = new int[n][d];
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		}
		int ans = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] x = new int[n][d];
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		}
		int ans = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}
}