from itertools import combinations

while True:

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

    if n == x == 0:

        break

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



from itertools import combinations

while True:

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

    if n == x == 0:

        break

    print((len([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(a + b + c == x for a, b, c in combinations(list(range(1, n + 1)), 3))))

from itertools import combinations

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

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