a, b = gets.chomp.split().map(&:to_i)
x = [] 
ct = 0
a.times do |n|
  x.push(gets.chomp.split().map(&:to_i))
end

a.times do |n|
  (1+n).upto(a-1) do |m|
    dist = 0
    b.times do |c|
      dist += (x[n][c] - x[m][c])**2
    end
    root = Math.sqrt(dist)
    ct += 1 if root.to_i == root
  end
end

puts ct