from itertools import combinations

while True:

    n, x = list(map(int, input().split()))

    if n == x == 0:

        break

    print((sum(1 for li in combinations(list(range(1, n + 1)), 3) if sum(li) == x)))

from itertools import combinations

while True:

    n, x = list(map(int, input().split()))

    if n == x == 0:

        break

    print((sum(1 for a, b, c in combinations(list(range(1, n + 1)), 3) if a + b + c == x)))

from itertools import combinations

while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    print((sum(1 for li in combinations(list(range(1, n + 1)), 3) if sum(li) == x)))

from itertools import combinations

while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    print(
        (sum(1 for a, b, c in combinations(list(range(1, n + 1)), 3) if a + b + c == x))
    )

-    print((sum(1 for li in combinations(list(range(1, n + 1)), 3) if sum(li) == x))) +    print( +        (sum(1 for a, b, c in combinations(list(range(1, n + 1)), 3) if a + b + c == x)) +    )