mat = readlines.map{|n| n.chomp.split(" ").map(&:to_i)}
n,d = mat.shift

cnt = 0
if d == 1
  puts n*(n-1)/2
else
  mat.combination(2).each do |arr|
    sum = 0
    arr[0].zip(arr[1]).each do |i,j|
      sum+=(i-j)**2
    end
    dist=Math.sqrt(sum)
    if dist.floor == dist
      cnt+=1
    end
  end
  puts(cnt)
end
