import java.util.Scanner;

public class Main {

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

} 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();
		int d = sc.nextInt();
		int[][] points = new int[n][d];
		int res = 0;
		
		for (int i = 0; i < n; i++) {
			int[] point = new int[d];
			for (int j = 0; j < d; j++) {
				point[j] = sc.nextInt();
			}
			points[i] = point;
		}
		
		for (int i = 0; i < n - 1; i++) {
			for (int j = i+1; j < n;j++) {
				double sum = 0.0;
				for (int k = 0; k < d; k++) {
					sum += (points[i][k] - points[j][k])*(points[i][k] - points[j][k]);
				}
				sum = Math.sqrt(sum);
				if ((sum - (int)sum) == 0) {res++;}
			}
		}
		
		System.out.println(res);
		
		sc.close();
	}

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

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

} public class Main {

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

} Main
import java.util.Scanner;

public class Main {

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

}
