while line = gets do
  n,x = line.chomp.split(" ").map{|x| x.to_i}
  if n==0 && x==0
    break
  end
  count = 0
  for i in (1..n).to_a.reverse do
    if i > x-3
      next
    elsif x > 3*i-3
      break
    end
    for j in (1..i-1).to_a.reverse do
      if i+j > x-1
        next
      elsif x-i-j > j-1
        break
      end
      count += 1
    end
  end
  printf("%d\n",count)
end
