while True:

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

    if n == 0 and x == 0: break

    c = 0

    for i in range(1, min(n-1,x/3)):

        for j in range(i+1, min(n,x/2)):

            for k in range(j+1, n+1):

                ijk = i + j + k

                if ijk == x:

                    c += 1

                    break

                elif ijk > x: break

    print(c)    
def count(n, x):

    c = 0

    for i in range(1, n-1):

        for j in range(i+1, n,):

            for k in range(j+1, n+1):

                s = i + j + k

                if s == x:

                    c += 1

                    break

                elif s > x: break

    return c



while True:

    p = list(map(int, input().split()))

    if p == [0, 0]: break

    print(count(*p))
while True:
    n, x = list(map(int, input().split()))
    if n == 0 and x == 0:
        break
    c = 0
    for i in range(1, min(n - 1, x / 3)):
        for j in range(i + 1, min(n, x / 2)):
            for k in range(j + 1, n + 1):
                ijk = i + j + k
                if ijk == x:
                    c += 1
                    break
                elif ijk > x:
                    break
    print(c)

def count(n, x):
    c = 0
    for i in range(1, n - 1):
        for j in range(
            i + 1,
            n,
        ):
            for k in range(j + 1, n + 1):
                s = i + j + k
                if s == x:
                    c += 1
                    break
                elif s > x:
                    break
    return c


while True:
    p = list(map(int, input().split()))
    if p == [0, 0]:
        break
    print(count(*p))

-while True: -    n, x = list(map(int, input().split())) -    if n == 0 and x == 0: -        break +def count(n, x): -    for i in range(1, min(n - 1, x / 3)): -        for j in range(i + 1, min(n, x / 2)): +    for i in range(1, n - 1): +        for j in range( +            i + 1, +            n, +        ): -                ijk = i + j + k -                if ijk == x: +                s = i + j + k +                if s == x: -                elif ijk > x: +                elif s > x: -    print(c) +    return c + + +while True: +    p = list(map(int, input().split())) +    if p == [0, 0]: +        break +    print(count(*p))