line = gets.chomp.split(" ").map(&:to_i)

n = line[0]
d = line[1]

points = []
ans = 0
n.times do
    new_point = gets.chomp.split(" ").map(&:to_i)
    points.each do |point|
        distance = 0
        square_d = 0
        d.times do |i|
            square_d += (point[i] - new_point[i]) ** 2
        end
        distance = square_d ** (1.0/2)
        if distance % 1 == 0
            ans += 1
        end
    end
    points.push(new_point)
end

puts ans
