n,d = gets.split.map(&:to_i)
x = Array.new(n,[])
n.times do |i|
  x[i] = gets.split.map(&:to_i)
end
count = 0
x.combination(2).to_a.each do |xx|
  sum = 0
  d.times do |i|
    sum += (xx[0][i] - xx[1][i]) ** 2
  end
  count += 1 if (sum ** (1/2.0)).to_s[-1] == "0"
end
puts count
