import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();

		int i = 0;
		int j = 0;
		int k = 0;
		int sum = 0;//それぞれの距離の二乗
		int judgeSum = 0;//距離が整数なものの合計
		int[][] x = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		}

		System.out.println(judgeSum);

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();

		int i = 0;
		int j = 0;
		int k = 0;
		int sum = 0;//それぞれの距離の二乗
		int judgeSum = 0;//距離が整数なものの合計
		int[][] x = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		}

		System.out.println(judgeSum);

	}

} Main public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();

		int i = 0;
		int j = 0;
		int k = 0;
		int sum = 0;//それぞれの距離の二乗
		int judgeSum = 0;//距離が整数なものの合計
		int[][] x = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		}

		System.out.println(judgeSum);

	} main {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();

		int i = 0;
		int j = 0;
		int k = 0;
		int sum = 0;//それぞれの距離の二乗
		int judgeSum = 0;//距離が整数なものの合計
		int[][] x = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		}

		System.out.println(judgeSum);

	} Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int d = s.nextInt(); d s.nextInt() s.nextInt s int i = 0; i 0 int j = 0; j 0 int k = 0; k 0 int sum = 0; sum 0 int judgeSum = 0; judgeSum 0 int[][] x = new int[n][d]; x new int[n][d] n d for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		} i = 0; i = 0 i 0 i < n i n i++ i++ i {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		} {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		} for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			} j = 0; j = 0 j 0 j < d j d j++ j++ j {//x
				x[i][j] = s.nextInt();
			} {//x
				x[i][j] = s.nextInt();
			} x[i][j] = s.nextInt() x[i][j] x[i] x i j s.nextInt() s.nextInt s if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			} i != 0 i 0 {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			} for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				} k = 0; k = 0 k 0 k < i k i k++ k++ k {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				} {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				} sum = 0 sum 0 if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					} i != k i k {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					} for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						} int m = 0; int m = 0; m 0 m < d m d m++ m++ m {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						} {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						} int sa = x[i][m] - x[k][m]; sa x[i][m] - x[k][m] x[i][m] x[i] x i m x[k][m] x[k] x k m int jijou = sa * sa; jijou sa * sa sa sa sum += jijou sum jijou judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0 judgeSum (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0 (Math.sqrt(sum) * 10) % 10 == 0 (Math.sqrt(sum) * 10) % 10 (Math.sqrt(sum) * 10) Math.sqrt(sum) Math.sqrt Math sum 10 10 0 1 0 System.out.println(judgeSum) System.out.println System.out System System.out judgeSum String[] args args public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();

		int i = 0;
		int j = 0;
		int k = 0;
		int sum = 0;//それぞれの距離の二乗
		int judgeSum = 0;//距離が整数なものの合計
		int[][] x = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		}

		System.out.println(judgeSum);

	}

} public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();

		int i = 0;
		int j = 0;
		int k = 0;
		int sum = 0;//それぞれの距離の二乗
		int judgeSum = 0;//距離が整数なものの合計
		int[][] x = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		}

		System.out.println(judgeSum);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();

		int i = 0;
		int j = 0;
		int k = 0;
		int sum = 0;//それぞれの距離の二乗
		int judgeSum = 0;//距離が整数なものの合計
		int[][] x = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {//x
				x[i][j] = s.nextInt();
			}
			if (i != 0) {
				for (k = 0; k < i; k++) {//
					sum = 0;
					if (i != k) {
						//各要素を二乗して足す
						for (int m = 0; m < d; m++) {
							int sa = x[i][m] - x[k][m];
							int jijou = sa * sa;
							sum += jijou;
						}
					}
					judgeSum += (Math.sqrt(sum) * 10) % 10 == 0 ? 1 : 0;
				}

			}
		}

		System.out.println(judgeSum);

	}

}
