import java.util.*;
public class Main {
	public static boolean calc(int[] a,int[] b) {
		double d = 0;
		for(int i = 0; i < a.length; i++) {
			d += Math.pow(a[i]-b[i], 2);
		}
		double s = Math.floor(Math.sqrt(d));
		
		if(s*s == d) return true;
		else return false;
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);

	}

} import java.util.*; util.* java public class Main {
	public static boolean calc(int[] a,int[] b) {
		double d = 0;
		for(int i = 0; i < a.length; i++) {
			d += Math.pow(a[i]-b[i], 2);
		}
		double s = Math.floor(Math.sqrt(d));
		
		if(s*s == d) return true;
		else return false;
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);

	}

} Main public static boolean calc(int[] a,int[] b) {
		double d = 0;
		for(int i = 0; i < a.length; i++) {
			d += Math.pow(a[i]-b[i], 2);
		}
		double s = Math.floor(Math.sqrt(d));
		
		if(s*s == d) return true;
		else return false;
	} calc {
		double d = 0;
		for(int i = 0; i < a.length; i++) {
			d += Math.pow(a[i]-b[i], 2);
		}
		double s = Math.floor(Math.sqrt(d));
		
		if(s*s == d) return true;
		else return false;
	} double d = 0; d 0 for(int i = 0; i < a.length; i++) {
			d += Math.pow(a[i]-b[i], 2);
		} int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
			d += Math.pow(a[i]-b[i], 2);
		} {
			d += Math.pow(a[i]-b[i], 2);
		} d += Math.pow(a[i]-b[i], 2) d Math.pow(a[i]-b[i], 2) Math.pow Math a[i]-b[i] a[i] a i b[i] b i 2 double s = Math.floor(Math.sqrt(d)); s Math.floor(Math.sqrt(d)) Math.floor Math Math.sqrt(d) Math.sqrt Math d if(s*s == d) return true;
		else return false; s*s == d s*s s s d return true; true return false; false int[] a a int[] b b public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);

	} main {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);

	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int N = stdIn.nextInt(); N stdIn.nextInt() stdIn.nextInt stdIn int D = stdIn.nextInt(); D stdIn.nextInt() stdIn.nextInt stdIn int[][] X = new int[N][D]; X new int[N][D] N D for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		} {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		} for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				X[i][j] = stdIn.nextInt();
			} {
				X[i][j] = stdIn.nextInt();
			} X[i][j] = stdIn.nextInt() X[i][j] X[i] X i j stdIn.nextInt() stdIn.nextInt stdIn int ans = 0; ans 0 for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		} {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		} for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			} int j = i+1; int j = i+1; j i+1 i 1 j < N j N j++ j++ j {
				if(calc(X[i],X[j])) {
					ans++;
				}
			} {
				if(calc(X[i],X[j])) {
					ans++;
				}
			} if(calc(X[i],X[j])) {
					ans++;
				} calc(X[i],X[j]) calc X[i] X i X[j] X j {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static boolean calc(int[] a,int[] b) {
		double d = 0;
		for(int i = 0; i < a.length; i++) {
			d += Math.pow(a[i]-b[i], 2);
		}
		double s = Math.floor(Math.sqrt(d));
		
		if(s*s == d) return true;
		else return false;
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);

	}

} public class Main {
	public static boolean calc(int[] a,int[] b) {
		double d = 0;
		for(int i = 0; i < a.length; i++) {
			d += Math.pow(a[i]-b[i], 2);
		}
		double s = Math.floor(Math.sqrt(d));
		
		if(s*s == d) return true;
		else return false;
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);

	}

} Main
import java.util.*;
public class Main {
	public static boolean calc(int[] a,int[] b) {
		double d = 0;
		for(int i = 0; i < a.length; i++) {
			d += Math.pow(a[i]-b[i], 2);
		}
		double s = Math.floor(Math.sqrt(d));
		
		if(s*s == d) return true;
		else return false;
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = stdIn.nextInt();
			}
		}
		
		int ans = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				if(calc(X[i],X[j])) {
					ans++;
				}
			}
		}
		
		System.out.println(ans);

	}

}