n, d = gets.strip.split.map(&:to_i)
ary = n.times.map {gets.split.map(&:to_i)}
count = 0
ary.combination(2) do |a, b|
  sum = 0
  d.times do |i|
    sum += (a[i] - b[i]) ** 2
  end

  dis = Math.sqrt(sum)
  count += 1 if (dis % 1).zero?
end

puts count