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[] square = new Integer[130];
		for (int i = 1; i <= 130; i++) {
			square[i - 1] = i * i;
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		}
		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[] square = new Integer[130];
		for (int i = 1; i <= 130; i++) {
			square[i - 1] = i * i;
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		}
		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[] square = new Integer[130];
		for (int i = 1; i <= 130; i++) {
			square[i - 1] = i * i;
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		}
		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[] square = new Integer[130];
		for (int i = 1; i <= 130; i++) {
			square[i - 1] = i * i;
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		}
		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[] square = new Integer[130]; square new Integer[130] 130 for (int i = 1; i <= 130; i++) {
			square[i - 1] = i * i;
		} int i = 1; int i = 1; i 1 i <= 130 i 130 i++ i++ i {
			square[i - 1] = i * i;
		} {
			square[i - 1] = i * i;
		} square[i - 1] = i * i square[i - 1] square i - 1 i 1 i * i i i int res = 0; res 0 for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		} {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		} for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			} {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			} int sum = 0; sum 0 for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				} {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				} sum += Math.pow(input[i][k] - input[j][k], 2) sum Math.pow(input[i][k] - input[j][k], 2) Math.pow Math input[i][k] - input[j][k] input[i][k] input[i] input i k input[j][k] input[j] input j k 2 if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				} Arrays.asList(square).contains(Integer.valueOf(sum)) Arrays.asList(square).contains Arrays.asList(square) Arrays.asList Arrays square Integer.valueOf(sum) Integer.valueOf Integer sum {
					res += 1;
				} res += 1 res 1 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[] square = new Integer[130];
		for (int i = 1; i <= 130; i++) {
			square[i - 1] = i * i;
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		}
		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[] square = new Integer[130];
		for (int i = 1; i <= 130; i++) {
			square[i - 1] = i * i;
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		}
		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[] square = new Integer[130];
		for (int i = 1; i <= 130; i++) {
			square[i - 1] = i * i;
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		}
		System.out.print(res);
	}
}
