def calDistance(y,z)
    d = 0
    y.length.times do |i|
        d += (y[i].to_f-z[i].to_f)**2
    end
    Math.sqrt(d)
end
N,D = gets.split.map(&:to_i)
X = Array.new(N).map{Array.new(D)}
N.times do |i|
    X[i] = gets.split.map(&:to_i)
end
res = 0
[*0..(N-1)].combination(2).to_a.each_with_index do |z, index|
    d = calDistance(X[z[0]],X[z[1]])
    is_integer = d == d.to_i
    res += 1 if is_integer
end
puts res