import java.util.Scanner;

public class Main {
	static int r = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}	
		}
		sc.close();
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		}
		System.out.println(r);
	}
	
	static void solve(int D, int[][] X, int idx1, int idx2) {
		int sum = 0;
		for(int i = 0; i < D; i++) {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		}
		boolean f = false;
		for(int i = 0; i <= sum; ++i) {
			if(i * i == sum) f = true;
		}
		if(f) r++;
		// double sqrt1 = Math.sqrt(sum);
		// int sqrt2 = (int)sqrt1;
		// if(sqrt1 == (double)sqrt2) r++;
		// System.out.println("# " + (sqrt1 == (double)sqrt2) + " = " + sum + " : " + sqrt1 + " " + sqrt2);
	}
}	 import java.util.Scanner; Scanner java.util public class Main {
	static int r = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}	
		}
		sc.close();
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		}
		System.out.println(r);
	}
	
	static void solve(int D, int[][] X, int idx1, int idx2) {
		int sum = 0;
		for(int i = 0; i < D; i++) {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		}
		boolean f = false;
		for(int i = 0; i <= sum; ++i) {
			if(i * i == sum) f = true;
		}
		if(f) r++;
		// double sqrt1 = Math.sqrt(sum);
		// int sqrt2 = (int)sqrt1;
		// if(sqrt1 == (double)sqrt2) r++;
		// System.out.println("# " + (sqrt1 == (double)sqrt2) + " = " + sum + " : " + sqrt1 + " " + sqrt2);
	}
} Main static int r = 0; r 0 public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}	
		}
		sc.close();
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		}
		System.out.println(r);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}	
		}
		sc.close();
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		}
		System.out.println(r);
	} 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[][] 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] = sc.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] = sc.nextInt();
			}	
		} {
			for(int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}	
		} for(int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				X[i][j] = sc.nextInt();
			} {
				X[i][j] = sc.nextInt();
			} X[i][j] = sc.nextInt() X[i][j] X[i] X i j sc.nextInt() sc.nextInt sc sc.close() sc.close sc for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		} {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		} for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				solve(D, X, i, j);
			} {
				solve(D, X, i, j);
			} solve(D, X, i, j) solve D X i j System.out.println(r) System.out.println System.out System System.out r String[] args args static void solve(int D, int[][] X, int idx1, int idx2) {
		int sum = 0;
		for(int i = 0; i < D; i++) {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		}
		boolean f = false;
		for(int i = 0; i <= sum; ++i) {
			if(i * i == sum) f = true;
		}
		if(f) r++;
		// double sqrt1 = Math.sqrt(sum);
		// int sqrt2 = (int)sqrt1;
		// if(sqrt1 == (double)sqrt2) r++;
		// System.out.println("# " + (sqrt1 == (double)sqrt2) + " = " + sum + " : " + sqrt1 + " " + sqrt2);
	} solve {
		int sum = 0;
		for(int i = 0; i < D; i++) {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		}
		boolean f = false;
		for(int i = 0; i <= sum; ++i) {
			if(i * i == sum) f = true;
		}
		if(f) r++;
		// double sqrt1 = Math.sqrt(sum);
		// int sqrt2 = (int)sqrt1;
		// if(sqrt1 == (double)sqrt2) r++;
		// System.out.println("# " + (sqrt1 == (double)sqrt2) + " = " + sum + " : " + sqrt1 + " " + sqrt2);
	} int sum = 0; sum 0 for(int i = 0; i < D; i++) {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		} int i = 0; int i = 0; i 0 i < D i D i++ i++ i {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		} {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		} int yx = Math.abs(X[idx1][i] - X[idx2][i]); yx Math.abs(X[idx1][i] - X[idx2][i]) Math.abs Math X[idx1][i] - X[idx2][i] X[idx1][i] X[idx1] X idx1 i X[idx2][i] X[idx2] X idx2 i sum += yx * yx sum yx * yx yx yx boolean f = false; f false for(int i = 0; i <= sum; ++i) {
			if(i * i == sum) f = true;
		} int i = 0; int i = 0; i 0 i <= sum i sum ++i ++i i {
			if(i * i == sum) f = true;
		} {
			if(i * i == sum) f = true;
		} if(i * i == sum) f = true; i * i == sum i * i i i sum f = true f true if(f) r++; f r++ r int D D int[][] X X int idx1 idx1 int idx2 idx2 public class Main {
	static int r = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}	
		}
		sc.close();
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		}
		System.out.println(r);
	}
	
	static void solve(int D, int[][] X, int idx1, int idx2) {
		int sum = 0;
		for(int i = 0; i < D; i++) {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		}
		boolean f = false;
		for(int i = 0; i <= sum; ++i) {
			if(i * i == sum) f = true;
		}
		if(f) r++;
		// double sqrt1 = Math.sqrt(sum);
		// int sqrt2 = (int)sqrt1;
		// if(sqrt1 == (double)sqrt2) r++;
		// System.out.println("# " + (sqrt1 == (double)sqrt2) + " = " + sum + " : " + sqrt1 + " " + sqrt2);
	}
} public class Main {
	static int r = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}	
		}
		sc.close();
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		}
		System.out.println(r);
	}
	
	static void solve(int D, int[][] X, int idx1, int idx2) {
		int sum = 0;
		for(int i = 0; i < D; i++) {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		}
		boolean f = false;
		for(int i = 0; i <= sum; ++i) {
			if(i * i == sum) f = true;
		}
		if(f) r++;
		// double sqrt1 = Math.sqrt(sum);
		// int sqrt2 = (int)sqrt1;
		// if(sqrt1 == (double)sqrt2) r++;
		// System.out.println("# " + (sqrt1 == (double)sqrt2) + " = " + sum + " : " + sqrt1 + " " + sqrt2);
	}
} Main
import java.util.Scanner;

public class Main {
	static int r = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}	
		}
		sc.close();
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				solve(D, X, i, j);
			}
		}
		System.out.println(r);
	}
	
	static void solve(int D, int[][] X, int idx1, int idx2) {
		int sum = 0;
		for(int i = 0; i < D; i++) {
			int yx = Math.abs(X[idx1][i] - X[idx2][i]);
			sum += yx * yx;
		}
		boolean f = false;
		for(int i = 0; i <= sum; ++i) {
			if(i * i == sum) f = true;
		}
		if(f) r++;
		// double sqrt1 = Math.sqrt(sum);
		// int sqrt2 = (int)sqrt1;
		// if(sqrt1 == (double)sqrt2) r++;
		// System.out.println("# " + (sqrt1 == (double)sqrt2) + " = " + sum + " : " + sqrt1 + " " + sqrt2);
	}
}	
