"use strict";
(function(input){
  input=input.trim();
  input=input.split(/\n/).map(str=>str.split(/\s+/).map(x=>x-0));
  const N=input[0][0],
        D=input[0][1];
  let ans=0;
  for(let i=1;i<=N;i++){
    for(let j=i+1;j<=N;j++){
      let dsquare=0,d=0;
      for(let k=0;k<D;k++){
        dsquare+=(input[i][k]-input[j][k])*(input[i][k]-input[j][k]);
      }
      d=Math.sqrt(dsquare);
      if(Math.abs(d-Math.round(d))<0.00000001)
        ans++;
    }
  }
  console.log(ans);
})(require("fs").readFileSync("/dev/stdin","utf8"));
