# 6:05
n, d = gets.to_s.split.map{|t|t.to_i}
x = Array.new(n){ gets.to_s.split.map{|t|t.to_i} }

def distance(p_i, p_j)
  
  dist = 0
  p_i.each_with_index do |x, i|
    dist += (x-p_j[i]) ** 2
  end
  dist
end

cnt = 0
n.times do |j|
  j.times do |i|
    dist = distance(x[i], x[j])
    cnt += 1 if dist == ((dist**0.5).round ** 2)
  end
end

puts cnt