n, d = gets.split.map(&:to_i)
X = []
n.times do
    line = gets.split.map(&:to_f)
    X << line
end
#print(X, "\n")
result = 0
for i in 0..(n-1)
    for j in (i+1)..(n-1)
        pre = 0
        for k in 0..(d-1)
          #print("i=",i,"j=",j,"k=",k,"\n")
          pre += ((X[i][k] - X[j][k]).abs)**2
        end
        #puts Math.sqrt(pre)
        if Math.sqrt(pre) == Math.sqrt(pre).to_i
            result += 1
        end
    end
end

puts result