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])))
while 1:

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

 if n+x==0:break

 print((len([1 for i in range(1,n-1)for j in range(i+1,n)if j<x-i-j<=n])))
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
                ]
            )
        )
    )

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

-                    for i in range(3, n + 1) -                    for j in range(2, x - i) -                    if x - i - j < j < i +                    for i in range(1, n - 1) +                    for j in range(i + 1, n) +                    if j < x - i - j <= n