while gets
  n, x = $_.split.map(&:to_i)
  if n == 0 && x == 0
    break
  end

  n_match = 0
  1.upto(n) do |a|
    a.upto(n) do |b|
      b.upto(n) do |c|
        if (a != b && b != c && c != a) && (a+b+c == x)
          n_match += 1
        end
      end
    end
  end
  puts n_match
end

