from itertools import combinations

while True:

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

 if n==m==0: break

 print((sum(1 for p in combinations(list(range(1,n+1)),3) if sum(p)==m)))
while 1:

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

 if n+x==0:break

 print((len([1 for i in range(3,n+1)for j in range(2,x-i)if x-i-j<j<i])))
from itertools import combinations

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

while 1:
    n, x = list(map(int, input().split()))
    if n + x == 0:
        break
    print(
        (
            len(
                [
                    1
                    for i in range(3, n + 1)
                    for j in range(2, x - i)
                    if x - i - j < j < i
                ]
            )
        )
    )

-from itertools import combinations - -while True: -    n, m = list(map(int, input().split())) -    if n == m == 0: +while 1: +    n, x = list(map(int, input().split())) +    if n + x == 0: -    print((sum(1 for p in combinations(list(range(1, n + 1)), 3) if sum(p) == m))) +    print( +        ( +            len( +                [ +                    1 +                    for i in range(3, n + 1) +                    for j in range(2, x - i) +                    if x - i - j < j < i +                ] +            ) +        ) +    )