'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(' '))
  const N = parseInt(input[0][0], 10)
  const D = parseInt(input[0][1], 10)
  const p = input.slice(1)
  let count = 0
  for (let i = 0; i < N; i++) {
    for (let j = i + 1; j < N; j++) {
      let sum = 0
      for (let k = 0; k < D; k++) {
        sum += Math.pow(p[i][k] - p[j][k], 2)
      }
      const sqrt = Math.sqrt(sum)
      if (sqrt === Math.floor(sqrt)) count++
    }
  }
  console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))
