import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] B = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);
		scan.close();
	}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] B = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);
		scan.close();
	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] B = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] B = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int D = scan.nextInt(); D scan.nextInt() scan.nextInt scan int[][] B = new int[N][D]; B new int[N][D] N D for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			}
		} {
			for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			}
		} for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				B[i][j] = scan.nextInt();
			} {
				B[i][j] = scan.nextInt();
			} B[i][j] = scan.nextInt() B[i][j] B[i] B i j scan.nextInt() scan.nextInt scan int ans = 0; ans 0 for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			}
		} {
			for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			}
		} for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			} {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			} double sum = 0; sum 0 for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				} {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				} double tmp = Math.abs((double)(B[i][k] - B[j][k])); tmp Math.abs((double)(B[i][k] - B[j][k])) Math.abs Math (double)(B[i][k] - B[j][k]) B[i][k] B[i] B i k B[j][k] B[j] B j k sum += Math.pow(tmp, 2) sum Math.pow(tmp, 2) Math.pow Math tmp 2 double num = Math.sqrt(sum); num Math.sqrt(sum) Math.sqrt Math sum if(num - (int)num == 0) {
					ans++;
				} num - (int)num == 0 num - (int)num num (int)num 0 {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] B = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);
		scan.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] B = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);
		scan.close();
	}

} Main
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] B = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				B[i][j] = scan.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				double sum = 0;
				for(int k = 0; k < D; k++) {
					double tmp = Math.abs((double)(B[i][k] - B[j][k]));
					sum += Math.pow(tmp, 2);
				}
				double num = Math.sqrt(sum);
				if(num - (int)num == 0) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);
		scan.close();
	}

}