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

points = []
ans = 0
n.times do
    input_point = gets.chomp.split(" ").map(&:to_i)
    points.each do |point|
        square_distance = 0.0
        d.times do |i|
            square_distance += (point[i] - input_point[i]) ** 2
        end
        distance = Math.sqrt(square_distance)
        if distance % 1 == 0
            ans += 1
        end
    end
    points.push(input_point)
end
puts ans
