import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int D = scanner.nextInt();
		int[][] arr = new int[N+1][D+1];
		int ans = 0;
		for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			}
		}
		/*for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j ++) {
				System.out.print(arr[i][j] + " ");
			}
			System.out.println();
		}*/
		for(int i = 1 ; i < N ; i ++) {
			for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		scanner.close();
	}
	
	public static boolean judge(int[] i, int[] j) {
		double ans = 0;
		for(int x = 1 ; x < i.length ;  x ++) {
			ans += (Math.pow(i[x] - j[x], 2));
		}
//		System.out.print(ans);
		ans = Math.pow(ans, 0.5);
//		System.out.println("    " + ans);
		if(ans%1 == 0) {
			return true;
		}
		return false;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int D = scanner.nextInt();
		int[][] arr = new int[N+1][D+1];
		int ans = 0;
		for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			}
		}
		/*for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j ++) {
				System.out.print(arr[i][j] + " ");
			}
			System.out.println();
		}*/
		for(int i = 1 ; i < N ; i ++) {
			for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		scanner.close();
	}
	
	public static boolean judge(int[] i, int[] j) {
		double ans = 0;
		for(int x = 1 ; x < i.length ;  x ++) {
			ans += (Math.pow(i[x] - j[x], 2));
		}
//		System.out.print(ans);
		ans = Math.pow(ans, 0.5);
//		System.out.println("    " + ans);
		if(ans%1 == 0) {
			return true;
		}
		return false;
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int D = scanner.nextInt();
		int[][] arr = new int[N+1][D+1];
		int ans = 0;
		for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			}
		}
		/*for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j ++) {
				System.out.print(arr[i][j] + " ");
			}
			System.out.println();
		}*/
		for(int i = 1 ; i < N ; i ++) {
			for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		scanner.close();
	} main {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int D = scanner.nextInt();
		int[][] arr = new int[N+1][D+1];
		int ans = 0;
		for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			}
		}
		/*for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j ++) {
				System.out.print(arr[i][j] + " ");
			}
			System.out.println();
		}*/
		for(int i = 1 ; i < N ; i ++) {
			for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int D = scanner.nextInt(); D scanner.nextInt() scanner.nextInt scanner int[][] arr = new int[N+1][D+1]; arr new int[N+1][D+1] N+1 N 1 D+1 D 1 int ans = 0; ans 0 for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			}
		} int i = 1 ; int i = 1 ; i 1 i <= N i N i ++ i ++ i {
			for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			}
		} {
			for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			}
		} for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			} int j = 1 ; int j = 1 ; j 1 j <= D j D j++ j++ j {
				arr[i][j] = scanner.nextInt();
			} {
				arr[i][j] = scanner.nextInt();
			} arr[i][j] = scanner.nextInt() arr[i][j] arr[i] arr i j scanner.nextInt() scanner.nextInt scanner for(int i = 1 ; i < N ; i ++) {
			for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			}
		} int i = 1 ; int i = 1 ; i 1 i < N i N i ++ i ++ i {
			for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			}
		} {
			for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			}
		} for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			} int j = i+1 ; int j = i+1 ; j i+1 i 1 j <= N j N j ++ j ++ j {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			} {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			} if(judge(arr[i],arr[j])) {
					ans++;
				} judge(arr[i],arr[j]) judge arr[i] arr i arr[j] arr j {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans scanner.close() scanner.close scanner String[] args args public static boolean judge(int[] i, int[] j) {
		double ans = 0;
		for(int x = 1 ; x < i.length ;  x ++) {
			ans += (Math.pow(i[x] - j[x], 2));
		}
//		System.out.print(ans);
		ans = Math.pow(ans, 0.5);
//		System.out.println("    " + ans);
		if(ans%1 == 0) {
			return true;
		}
		return false;
	} judge {
		double ans = 0;
		for(int x = 1 ; x < i.length ;  x ++) {
			ans += (Math.pow(i[x] - j[x], 2));
		}
//		System.out.print(ans);
		ans = Math.pow(ans, 0.5);
//		System.out.println("    " + ans);
		if(ans%1 == 0) {
			return true;
		}
		return false;
	} double ans = 0; ans 0 for(int x = 1 ; x < i.length ;  x ++) {
			ans += (Math.pow(i[x] - j[x], 2));
		} int x = 1 ; int x = 1 ; x 1 x < i.length x i.length i i.length x ++ x ++ x {
			ans += (Math.pow(i[x] - j[x], 2));
		} {
			ans += (Math.pow(i[x] - j[x], 2));
		} ans += (Math.pow(i[x] - j[x], 2)) ans (Math.pow(i[x] - j[x], 2)) Math.pow Math i[x] - j[x] i[x] i x j[x] j x 2 ans = Math.pow(ans, 0.5) ans Math.pow(ans, 0.5) Math.pow Math ans 0.5 if(ans%1 == 0) {
			return true;
		} ans%1 == 0 ans%1 ans 1 0 {
			return true;
		} return true; true return false; false int[] i i int[] j j public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int D = scanner.nextInt();
		int[][] arr = new int[N+1][D+1];
		int ans = 0;
		for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			}
		}
		/*for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j ++) {
				System.out.print(arr[i][j] + " ");
			}
			System.out.println();
		}*/
		for(int i = 1 ; i < N ; i ++) {
			for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		scanner.close();
	}
	
	public static boolean judge(int[] i, int[] j) {
		double ans = 0;
		for(int x = 1 ; x < i.length ;  x ++) {
			ans += (Math.pow(i[x] - j[x], 2));
		}
//		System.out.print(ans);
		ans = Math.pow(ans, 0.5);
//		System.out.println("    " + ans);
		if(ans%1 == 0) {
			return true;
		}
		return false;
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int D = scanner.nextInt();
		int[][] arr = new int[N+1][D+1];
		int ans = 0;
		for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			}
		}
		/*for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j ++) {
				System.out.print(arr[i][j] + " ");
			}
			System.out.println();
		}*/
		for(int i = 1 ; i < N ; i ++) {
			for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		scanner.close();
	}
	
	public static boolean judge(int[] i, int[] j) {
		double ans = 0;
		for(int x = 1 ; x < i.length ;  x ++) {
			ans += (Math.pow(i[x] - j[x], 2));
		}
//		System.out.print(ans);
		ans = Math.pow(ans, 0.5);
//		System.out.println("    " + ans);
		if(ans%1 == 0) {
			return true;
		}
		return false;
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int D = scanner.nextInt();
		int[][] arr = new int[N+1][D+1];
		int ans = 0;
		for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j++) {
				arr[i][j] = scanner.nextInt();
			}
		}
		/*for(int i = 1 ; i <= N ; i ++) {
			for(int j = 1 ; j <= D ; j ++) {
				System.out.print(arr[i][j] + " ");
			}
			System.out.println();
		}*/
		for(int i = 1 ; i < N ; i ++) {
			for(int j = i+1 ; j <= N ; j ++) {
				if(judge(arr[i],arr[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		scanner.close();
	}
	
	public static boolean judge(int[] i, int[] j) {
		double ans = 0;
		for(int x = 1 ; x < i.length ;  x ++) {
			ans += (Math.pow(i[x] - j[x], 2));
		}
//		System.out.print(ans);
		ans = Math.pow(ans, 0.5);
//		System.out.println("    " + ans);
		if(ans%1 == 0) {
			return true;
		}
		return false;
	}
}
