import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt(), i, j;
		int[][] p = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (i = 0; i < n - 1; i++) {
			for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} 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(), d = sc.nextInt(), i, j;
		int[][] p = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (i = 0; i < n - 1; i++) {
			for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt(), i, j;
		int[][] p = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (i = 0; i < n - 1; i++) {
			for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt(), i, j;
		int[][] p = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (i = 0; i < n - 1; i++) {
			for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			}
		}
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc d = sc.nextInt() d sc.nextInt() sc.nextInt sc i i j; j int[][] p = new int[n][d]; p new int[n][d] n d for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			}
		} i = 0; i = 0 i 0 i < n i n i++ i++ i {
			for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			}
		} {
			for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			}
		} for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			} j = 0; j = 0 j 0 j < d j d j++ j++ j {
				p[i][j] = sc.nextInt();
			} {
				p[i][j] = sc.nextInt();
			} p[i][j] = sc.nextInt() p[i][j] p[i] p i j sc.nextInt() sc.nextInt sc int count = 0; count 0 for (i = 0; i < n - 1; i++) {
			for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			}
		} i = 0; i = 0 i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			}
		} {
			for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			}
		} for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			} j = i + 1; 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 += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			} {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			} int sum = 0; sum 0 for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				} {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				} sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]) sum (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]) (p[i][k] - p[j][k]) p[i][k] p[i] p i k p[j][k] p[j] p j k (p[i][k] - p[j][k]) p[i][k] p[i] p i k p[j][k] p[j] p j k double sqrt = Math.sqrt(sum); sqrt Math.sqrt(sum) Math.sqrt Math sum if (0 == sqrt % 1) {
					count++;
				} 0 == sqrt % 1 0 sqrt % 1 sqrt 1 {
					count++;
				} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt(), i, j;
		int[][] p = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (i = 0; i < n - 1; i++) {
			for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt(), i, j;
		int[][] p = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (i = 0; i < n - 1; i++) {
			for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), d = sc.nextInt(), i, j;
		int[][] p = new int[n][d];
		for (i = 0; i < n; i++) {
			for (j = 0; j < d; j++) {
				p[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (i = 0; i < n - 1; i++) {
			for (j = i + 1; j < n; j++) {
				int sum = 0;
				for (int k = 0; k < d; k++) {
					sum += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
				}
				double sqrt = Math.sqrt(sum);
				if (0 == sqrt % 1) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}
