require 'complex'

n, d = gets.chomp.split(" ").map(&:to_i)
spots = []
n.times do
  spots << gets.chomp.split(" ").map(&:to_i)
end

sum = 0
spots.each_with_index do |spot1, index1|
  spots.each_with_index do |spot2, index2|
    if spot1 == spot2
      next
    end
    distance = 0.0
    d.times do |dimention|
      distance += (spot1[dimention] - spot2[dimention]).abs.to_f ** 2
    end
    distance = Math.sqrt(distance)
    if distance.ceil == distance.floor
      sum += 1
    end
  end
end

puts sum / 2