n, _ = gets.chomp.split.map(&:to_i)
x = Array.new(n) { gets.chomp.split.map(&:to_i) }
res = 0
(0..n - 2).each do |i|
  (i + 1..n - 1).each do |j|
    dist2 = x[i].zip(x[j]).map {|y, z| (y - z) ** 2 }.inject(:+)
    res += 1 if Math::sqrt(dist2).to_i == Math::sqrt(dist2)
  end
end
puts res