// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  
  var input1 = input[0].split(" ");
  var maxH = Number(input1[0]);
  var maxW = Number(input1[1]);
  var array = [];
  var count = 0;
  for(var i=1; i <= maxH; i++){
    array.push(input[i].split(" "));
  }
  var sum  = function(arr) {
    return arr.reduce(function(prev, current, i, arr) {
        return prev+current;
    });
  };

  function combinations(num,select) {
    var top = num;
    for (var i = 1; i < select; i++) {
      top = top * (top - i);
    }
    var buttom = select;
    for (var j = 1; j < select; j++) {
      buttom = buttom * (buttom - j)
    }
    return top/buttom;
    
  };
  
  if(maxW === 1){
    if(maxH > 2){
      count = combinations(maxH,2);
    }
    else{
      count = 1;
    }
  }
  else{
    for(var j = 0; j < maxH; j++){
      var distance = [];
      for(var all = 0; all < maxH; all++) {
        if(all < j){
          for(var h = 0; h < maxW; h++){
            var pointArray = (array[j]);
            var pointNextArray = (array[all]);
            var cal = pointArray[h] - pointNextArray[h];
            distance.push(Math.pow(cal, 2));
          }
          var cal_result = Math.sqrt(sum(distance));
          console.log(cal_result)
          if(Number.isInteger(cal_result)){
            count = count + 1;
          }
        }
      }
    }
  }
  
 	console.log(count);
 }
 //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));