loop do
  n, x = gets.split.map(&:to_i)
  exit if n == 0 && x == 0
  cnt = 0
  (1..n-2).each do | i |
    (i+1..n-1).each do | j |
      (j+1..n).each do | k |
        cnt += 1 if i + j + k == x
      end
    end
  end
  puts cnt
end