n, d = gets.strip.split.map(&:to_i)
x = Array.new(n, Array.new(d, 0) )

for i in 0...n
  x[i]=gets.strip.split.map(&:to_i)
end

res=0
for i in 0...n
  for j in i+1...n
    sum2=0
    for k in 0...d
      sum2+=(x[i][k]-x[j][k])**2
    end
    len=Math.sqrt(sum2)
    if(len==len.floor)
      res+=1
    end
  end
end

puts res
