import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] input = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			}
		}
		Integer[] sq = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441,
				484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,
				1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249,
				3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476,
				5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
				8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449,
				11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884,
				15129, 15376, 15625, 15876 };
		int res = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		}
		System.out.print(res);
	}
} import java.util.Arrays; Arrays java.util 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 = sc.nextInt();
		int D = sc.nextInt();
		int[][] input = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			}
		}
		Integer[] sq = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441,
				484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,
				1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249,
				3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476,
				5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
				8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449,
				11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884,
				15129, 15376, 15625, 15876 };
		int res = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		}
		System.out.print(res);
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] input = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			}
		}
		Integer[] sq = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441,
				484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,
				1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249,
				3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476,
				5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
				8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449,
				11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884,
				15129, 15376, 15625, 15876 };
		int res = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		}
		System.out.print(res);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] input = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			}
		}
		Integer[] sq = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441,
				484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,
				1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249,
				3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476,
				5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
				8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449,
				11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884,
				15129, 15376, 15625, 15876 };
		int res = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		}
		System.out.print(res);
	} 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[][] input = new int[N][D]; input new int[N][D] N D for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				input[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++) {
				input[i][j] = sc.nextInt();
			}
		} {
			for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			}
		} for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				input[i][j] = sc.nextInt();
			} {
				input[i][j] = sc.nextInt();
			} input[i][j] = sc.nextInt() input[i][j] input[i] input i j sc.nextInt() sc.nextInt sc Integer[] sq = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441,
				484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,
				1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249,
				3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476,
				5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
				8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449,
				11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884,
				15129, 15376, 15625, 15876 }; sq { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441,
				484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,
				1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249,
				3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476,
				5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
				8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449,
				11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884,
				15129, 15376, 15625, 15876 } 0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 729 784 841 900 961 1024 1089 1156 1225 1296 1369 1444 1521 1600 1681 1764 1849 1936 2025 2116 2209 2304 2401 2500 2601 2704 2809 2916 3025 3136 3249 3364 3481 3600 3721 3844 3969 4096 4225 4356 4489 4624 4761 4900 5041 5184 5329 5476 5625 5776 5929 6084 6241 6400 6561 6724 6889 7056 7225 7396 7569 7744 7921 8100 8281 8464 8649 8836 9025 9216 9409 9604 9801 10000 10201 10404 10609 10816 11025 11236 11449 11664 11881 12100 12321 12544 12769 12996 13225 13456 13689 13924 14161 14400 14641 14884 15129 15376 15625 15876 int res = 0; res 0 for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		} {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		} for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			} {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			} int dsq = 0; dsq 0 for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				} int d = 0; int d = 0; d 0 d < D d D d++ d++ d {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				} {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				} dsq += Math.pow((input[i][d] - input[j][d]), 2) dsq Math.pow((input[i][d] - input[j][d]), 2) Math.pow Math (input[i][d] - input[j][d]) input[i][d] input[i] input i d input[j][d] input[j] input j d 2 if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				} Arrays.asList(sq).contains(Integer.valueOf((dsq))) Arrays.asList(sq).contains Arrays.asList(sq) Arrays.asList Arrays sq Integer.valueOf((dsq)) Integer.valueOf Integer (dsq) {
					res++;
				} res++ res System.out.print(res) System.out.print System.out System System.out res String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] input = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			}
		}
		Integer[] sq = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441,
				484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,
				1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249,
				3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476,
				5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
				8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449,
				11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884,
				15129, 15376, 15625, 15876 };
		int res = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		}
		System.out.print(res);
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] input = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			}
		}
		Integer[] sq = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441,
				484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,
				1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249,
				3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476,
				5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
				8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449,
				11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884,
				15129, 15376, 15625, 15876 };
		int res = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		}
		System.out.print(res);
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] input = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			}
		}
		Integer[] sq = { 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441,
				484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600,
				1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249,
				3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476,
				5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
				8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449,
				11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884,
				15129, 15376, 15625, 15876 };
		int res = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int dsq = 0;
				for (int d = 0; d < D; d++) {
					dsq += Math.pow((input[i][d] - input[j][d]), 2);
				}
				if (Arrays.asList(sq).contains(Integer.valueOf((dsq)))) {
					res++;
				}
			}
		}
		System.out.print(res);
	}
}
