require 'complex'
N,D = gets.chomp.split(" ").map(&:to_i)
points = []
N.times do
    points << gets.chomp.split(" ").map(&:to_i)
end
sum = 0
0.upto(N-1) do |i|
    (i+1).upto(N-1) do |j|
        a_point = points[i]
        b_point = points[j]
        length = 0
        a_point.each_with_index do |point,k|

            length += (b_point[k] - point)**2
        end
        if Math.sqrt(length) ==  Math.sqrt(length).to_i
            sum += 1
        end
    end
end
puts sum