

function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var D = parseInt(input[0].split(" ")[1]);
  input.shift();
  var X = input.map(i => i.split(" ").map(i => parseInt(i)));
  X.splice(N,X.length-N);
  var ans=0;
  for(var i = 0;i<N;i++){
    for(var j=i+1;j<N;j++){
      var sum=0;
      for(var k=0;k<D;k++){
        sum+=Math.pow(X[j][k]-X[i][k],2)
      }
      if(Math.sqrt(sum)==Math.floor(Math.sqrt(sum))){
        ans++;
      }
    }
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));