import java.util.Scanner;

public class Main {
	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];
		int ans = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = stdIn.nextInt();
			}
		}

		for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	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];
		int ans = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = stdIn.nextInt();
			}
		}

		for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
} Main 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];
		int ans = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = stdIn.nextInt();
			}
		}

		for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			}
		}
		System.out.println(ans);
		stdIn.close();
	} main {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		int X[][] = new int[N][D];
		int ans = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = stdIn.nextInt();
			}
		}

		for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			}
		}
		System.out.println(ans);
		stdIn.close();
	} 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 int ans = 0; ans 0 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 for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 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 tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			}
		} {
			for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			}
		} for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			} {
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			} double tmp = 0; tmp 0 for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					tmp += Math.pow(X[j][k] - X[i][k],2);
				} {
					tmp += Math.pow(X[j][k] - X[i][k],2);
				} tmp += Math.pow(X[j][k] - X[i][k],2) tmp Math.pow(X[j][k] - X[i][k],2) Math.pow Math X[j][k] - X[i][k] X[j][k] X[j] X j k X[i][k] X[i] X i k 2 double sq = Math.sqrt(tmp); sq Math.sqrt(tmp) Math.sqrt Math tmp if((sq - (int)sq) == 0){
					ans++;
				} (sq - (int)sq) == 0 (sq - (int)sq) sq (int)sq 0 {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans stdIn.close() stdIn.close stdIn String[] args args public class Main {
	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];
		int ans = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = stdIn.nextInt();
			}
		}

		for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
} public class Main {
	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];
		int ans = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = stdIn.nextInt();
			}
		}

		for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
} Main
import java.util.Scanner;

public class Main {
	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];
		int ans = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = stdIn.nextInt();
			}
		}

		for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
}