loop do
  ans = 0
  a, b, c = [1, 2, 3]
  n, x = gets.split.map(&:to_i)
  break if n == 0 && x == 0
  loop do
    ans += 1 if a + b + c == x
    puts "a: #{a}, b: #{b}, c: #{c} = #{a+b+c}"
    if c < n && a + b + c < x
      c += 1
    else
      if b+1 == c
        if a+1 == b
          break
        else
          a += 1
          b = a+1
          c = b+1
        end
      else
        b += 1
        c = b+1
      end
    end
  end
  puts ans
end