import java.util.Scanner;
 class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int count = 0;
		double[][] a = new double[N][D];
		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				 a[i][j]  = sc.nextInt(); 
			}
		}
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		}
	}
		System.out.println(count);
}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int count = 0;
		double[][] a = new double[N][D];
		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				 a[i][j]  = sc.nextInt(); 
			}
		}
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		}
	}
		System.out.println(count);
}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int count = 0;
		double[][] a = new double[N][D];
		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				 a[i][j]  = sc.nextInt(); 
			}
		}
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		}
	}
		System.out.println(count);
} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int count = 0;
		double[][] a = new double[N][D];
		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				 a[i][j]  = sc.nextInt(); 
			}
		}
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		}
	}
		System.out.println(count);
} 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 count = 0; count 0 double[][] a = new double[N][D]; a new double[N][D] N D for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				 a[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++) {
				 a[i][j]  = sc.nextInt(); 
			}
		} {
			for(int j=0;j<D;j++) {
				 a[i][j]  = sc.nextInt(); 
			}
		} for(int j=0;j<D;j++) {
				 a[i][j]  = sc.nextInt(); 
			} int j=0; int j=0; j 0 j<D j D j++ j++ j {
				 a[i][j]  = sc.nextInt(); 
			} {
				 a[i][j]  = sc.nextInt(); 
			} a[i][j]  = sc.nextInt() a[i][j] a[i] a i j sc.nextInt() sc.nextInt sc for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		}
	} int i=0; int i=0; i 0 i<N-1 i N-1 N 1 i++ i++ i {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		}
	} {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		}
	} for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		} 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++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		} {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		} double sum = 0; sum 0 for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			} int k=0; int k=0; k 0 k<D k D k++ k++ k {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			} {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			} sum +=  Math.pow(a[i][k]-a[j][k],2) sum Math.pow(a[i][k]-a[j][k],2) Math.pow Math a[i][k]-a[j][k] a[i][k] a[i] a i k a[j][k] a[j] a j k 2 sum=Math.sqrt(sum) sum Math.sqrt(sum) Math.sqrt Math sum if(sum%1==0) {
					count++;
				} sum%1==0 sum%1 sum 1 0 {
					count++;
				} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.Scanner;
 class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int count = 0;
		double[][] a = new double[N][D];
		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				 a[i][j]  = sc.nextInt(); 
			}
		}
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		}
	}
		System.out.println(count);
}
}
