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

xs = []
n.times do
  xs << gets.split.map(&:to_f)
end

ans = 0
(0..n-2).each do |i|
  ((i+1)..n-1).each do |j|
    dis = 0
    (0..d-1).each do |dd|
      dis += (xs[i][dd] - xs[j][dd]) ** 2
    end
    val = Math.sqrt(dis)
    if val == val.to_i
      ans += 1
    end
  end
end
puts ans