n, d = gets.split("\s").map(&:to_i)

count = 0
x = []

n.times do |i|
  x << gets.split("\s").map(&:to_i)
end

0.upto(n-1) do |i|
  (i+1).upto(n-1) do |j|
    x_zip = x[i].zip x[j]
    sum = 0
    x_zip.each do |x_y| sum += (x_y[0] - x_y[-1])**2 end
    dist = Math.sqrt(sum)
    
    count += 1 if dist - dist.to_i == 0
  end
end

p count