const main = (inputs) => {
  var N = inputs[0].split(" ")[0];
  var D = inputs[0].split(" ")[1];
  var list = inputs.filter((v,i)=>i>0).map(v=>v.split(" "));
  var ans = 0;
  for(var i=0;i<N;i++){
    for(var j=i+1;j<N;j++){
      var dis = 0;
      for(var k=0;k<D;k++){
        dis += Math.pow(list[i][k]-list[j][k], 2);
      }
      if(Math.sqrt(dis) == ~~Math.sqrt(dis)) ans++;
    }
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));
