require 'complex'

n,d = gets.split(" ").map{|e| e.to_i}
count =0
dimension = []
n.times do
  dimension << gets.split(" ").map{|e| e.to_i}
end

dimension.combination(2).each do |a,b|
  sum = 0
  a.zip(b).each do|item|
    sum += (item[0]-item[1])**2
  end
  tmp = Math.sqrt(sum)
  count += 1 if (tmp - tmp.to_i) == 0
end

puts count