function main(input) {
  const inputList = input.split(/\n/);
  const oneLineList = inputList[0].split(/\s/).map(inp => formatNum(inp));
  const N = oneLineList[0];
  const D = oneLineList[1];
  const valueList = [];
  for (var i = 1; i <= N; i++) {
    valueList.push(inputList[i].split(/\s/).map(il => formatNum(il)));
  }
  var listA = [];
  var listB = [];
  var count = 0;
  for (var j = 0; j < valueList.length; j++) {
    for (var l = j + 1; l < valueList.length; l++) {
      if (l !== valueList.length) {
        listA = valueList[j];
        listB = valueList[l];
        var calcValue = 0;
        for (var k = 0; k < D; k++) {
          calcValue += (listA[k] - listB[k]) * (listA[k] - listB[k]);
        }
        var sqrtNum = Math.sqrt(calcValue);
        if (Number.isInteger(sqrtNum)) {
          count++
        }
      }
    }
  }
  console.log(count);
};

// 文字列を数値に変換
function formatNum(str) {
  return Number(str);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));
