require "complex"

N, D = gets.chomp.split.map(&:to_i)
X = N.times.map { gets.chomp.split.map(&:to_f) }

ans = 0
X.combination(2) { |y, z|
  sum = 0
  for i in 0..D - 1
    sum += (y[i] - z[i]) ** 2
  end
  n = 1
  while n ** 2 <= sum
    if n ** 2 == sum
      ans += 1
      break
    end
    n += 1
  end
}

puts ans
