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

x = []
n.times{x << gets.split.map(&:to_i)}

ans = 0
(0..n-1).to_a.combination(2) do |arr|
    a = 0.0
    d.times do |j|
        a += (x[arr[0]][j] - x[arr[1]][j]) ** 2
    end
    ans += 1 if Math.sqrt(a).denominator == 1
end

puts ans