import java.util.Scanner;

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 < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = sc.nextInt();
			}
		}

		int cnt = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);

		sc.close();
	}

	static double calcDistance(int[] a, int[] b) {
		double sum = 0;
		for (int i = 0; i < a.length; i++) {
			sum += Math.pow(a[i] - b[i], 2.0);
		}
		return Math.sqrt(sum);
	}

	static boolean isInteger(double d) {
		return d == (int) d;
	}
} import java.util.Scanner; Scanner java.util 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 < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = sc.nextInt();
			}
		}

		int cnt = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);

		sc.close();
	}

	static double calcDistance(int[] a, int[] b) {
		double sum = 0;
		for (int i = 0; i < a.length; i++) {
			sum += Math.pow(a[i] - b[i], 2.0);
		}
		return Math.sqrt(sum);
	}

	static boolean isInteger(double d) {
		return d == (int) d;
	}
} 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 < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = sc.nextInt();
			}
		}

		int cnt = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);

		sc.close();
	} 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 < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = sc.nextInt();
			}
		}

		int cnt = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);

		sc.close();
	} 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 < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = sc.nextInt();
			}
		} 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] = sc.nextInt();
			}
		} {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = sc.nextInt();
			}
		} for (int j = 0; j < x[i].length; j++) {
				x[i][j] = sc.nextInt();
			} 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] = 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 < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			}
		} 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++) {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			}
		} {
			for (int j = i + 1; j < x.length; j++) {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			}
		} for (int j = i + 1; j < x.length; j++) {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			} 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 {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			} {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			} if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				} isInteger(calcDistance(x[i], x[j])) isInteger calcDistance(x[i], x[j]) calcDistance x[i] x i x[j] x j {
					cnt++;
				} cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt sc.close() sc.close sc String[] args args static double calcDistance(int[] a, int[] b) {
		double sum = 0;
		for (int i = 0; i < a.length; i++) {
			sum += Math.pow(a[i] - b[i], 2.0);
		}
		return Math.sqrt(sum);
	} calcDistance {
		double sum = 0;
		for (int i = 0; i < a.length; i++) {
			sum += Math.pow(a[i] - b[i], 2.0);
		}
		return Math.sqrt(sum);
	} double sum = 0; sum 0 for (int i = 0; i < a.length; i++) {
			sum += Math.pow(a[i] - b[i], 2.0);
		} int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
			sum += Math.pow(a[i] - b[i], 2.0);
		} {
			sum += Math.pow(a[i] - b[i], 2.0);
		} sum += Math.pow(a[i] - b[i], 2.0) sum Math.pow(a[i] - b[i], 2.0) Math.pow Math a[i] - b[i] a[i] a i b[i] b i 2.0 return Math.sqrt(sum); Math.sqrt(sum) Math.sqrt Math sum int[] a a int[] b b static boolean isInteger(double d) {
		return d == (int) d;
	} isInteger {
		return d == (int) d;
	} return d == (int) d; d == (int) d d (int) d double d d
import java.util.Scanner;

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 < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = sc.nextInt();
			}
		}

		int cnt = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				if (isInteger(calcDistance(x[i], x[j]))) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);

		sc.close();
	}

	static double calcDistance(int[] a, int[] b) {
		double sum = 0;
		for (int i = 0; i < a.length; i++) {
			sum += Math.pow(a[i] - b[i], 2.0);
		}
		return Math.sqrt(sum);
	}

	static boolean isInteger(double d) {
		return d == (int) d;
	}
}
