import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		}
		System.out.println(cnt);
	}

	private static int solve(int[] x1, int[] x2) {
		double sum = 0;
		int size = x1.length;
		for (int i = 0; i < size; i++) {
			sum += Math.pow(x1[i] - x2[i], 2);
		}
		sum = Math.pow(sum, 0.5);
		if (sum - Math.round(sum) == 0) {
			return 1;
		} else {
			return 0;
		}

	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		}
		System.out.println(cnt);
	}

	private static int solve(int[] x1, int[] x2) {
		double sum = 0;
		int size = x1.length;
		for (int i = 0; i < size; i++) {
			sum += Math.pow(x1[i] - x2[i], 2);
		}
		sum = Math.pow(sum, 0.5);
		if (sum - Math.round(sum) == 0) {
			return 1;
		} else {
			return 0;
		}

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		}
		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		}
		System.out.println(cnt);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int[][] x = new int[n][d]; x new int[n][d] n d for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		} {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		} for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				x[i][j] = sc.nextInt();
			} {
				x[i][j] = sc.nextInt();
			} x[i][j] = sc.nextInt() x[i][j] x[i] x i j sc.nextInt() sc.nextInt sc int cnt = 0; cnt 0 for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		} {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		} for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				cnt += solve(x[i], x[j]);
			} {
				cnt += solve(x[i], x[j]);
			} cnt += solve(x[i], x[j]) cnt solve(x[i], x[j]) solve x[i] x i x[j] x j System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args private static int solve(int[] x1, int[] x2) {
		double sum = 0;
		int size = x1.length;
		for (int i = 0; i < size; i++) {
			sum += Math.pow(x1[i] - x2[i], 2);
		}
		sum = Math.pow(sum, 0.5);
		if (sum - Math.round(sum) == 0) {
			return 1;
		} else {
			return 0;
		}

	} solve {
		double sum = 0;
		int size = x1.length;
		for (int i = 0; i < size; i++) {
			sum += Math.pow(x1[i] - x2[i], 2);
		}
		sum = Math.pow(sum, 0.5);
		if (sum - Math.round(sum) == 0) {
			return 1;
		} else {
			return 0;
		}

	} double sum = 0; sum 0 int size = x1.length; size x1.length x1 x1.length for (int i = 0; i < size; i++) {
			sum += Math.pow(x1[i] - x2[i], 2);
		} int i = 0; int i = 0; i 0 i < size i size i++ i++ i {
			sum += Math.pow(x1[i] - x2[i], 2);
		} {
			sum += Math.pow(x1[i] - x2[i], 2);
		} sum += Math.pow(x1[i] - x2[i], 2) sum Math.pow(x1[i] - x2[i], 2) Math.pow Math x1[i] - x2[i] x1[i] x1 i x2[i] x2 i 2 sum = Math.pow(sum, 0.5) sum Math.pow(sum, 0.5) Math.pow Math sum 0.5 if (sum - Math.round(sum) == 0) {
			return 1;
		} else {
			return 0;
		} sum - Math.round(sum) == 0 sum - Math.round(sum) sum Math.round(sum) Math.round Math sum 0 {
			return 1;
		} return 1; 1 {
			return 0;
		} return 0; 0 int[] x1 x1 int[] x2 x2 public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		}
		System.out.println(cnt);
	}

	private static int solve(int[] x1, int[] x2) {
		double sum = 0;
		int size = x1.length;
		for (int i = 0; i < size; i++) {
			sum += Math.pow(x1[i] - x2[i], 2);
		}
		sum = Math.pow(sum, 0.5);
		if (sum - Math.round(sum) == 0) {
			return 1;
		} else {
			return 0;
		}

	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		}
		System.out.println(cnt);
	}

	private static int solve(int[] x1, int[] x2) {
		double sum = 0;
		int size = x1.length;
		for (int i = 0; i < size; i++) {
			sum += Math.pow(x1[i] - x2[i], 2);
		}
		sum = Math.pow(sum, 0.5);
		if (sum - Math.round(sum) == 0) {
			return 1;
		} else {
			return 0;
		}

	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		}
		System.out.println(cnt);
	}

	private static int solve(int[] x1, int[] x2) {
		double sum = 0;
		int size = x1.length;
		for (int i = 0; i < size; i++) {
			sum += Math.pow(x1[i] - x2[i], 2);
		}
		sum = Math.pow(sum, 0.5);
		if (sum - Math.round(sum) == 0) {
			return 1;
		} else {
			return 0;
		}

	}
}
