function Main(input) {
  	input = input.split("\n");
  	i = 0;
  	x = [];
	counter = 0;
  	N =1000000;
    D = 0;
   for(i=0;i<=N;i++){
      	num = input[i].split(/\s+/);
      	littleX = [];
		if(i==0){
          N = num[0];
          D = num[1];
        }else{
        	for(j=0;j<D;j++){
	          littleX.push(num[j]);
        	}
            x.push(littleX);
        }

     	//console.log("i= "+i+"N:" + N + ",D:"+D + ",littleX:" + littleX);
    }

  	for(i=0;i<N;i++){
      	for(k=i+1;k<N;k++){
	      	//console.log("check "+i+"to"+k);
          	//console.log(x[i]);
          	//console.log(x[k]);
          	sum = 0;
          	for(j=0;j<D;j++){
            	sum+= Math.abs((x[i][j] - x[k][j])*(x[i][j] - x[k][j]));
            }
          	//console.log(sum);
          	//console.log(Math.sqrt(sum));
          	//console.log(Number.isInteger(Math.sqrt(sum)));
          	if(Number.isInteger(Math.sqrt(sum)) === true){
            	counter++;
            }
        }
    }
  	console.log(counter);
  	
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));