while True:

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

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

    c = 0

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

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

            ij = i + j

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

                if ij+k == x:

                    c += 1

    print(c)    
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+1,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)    
while True:
    n, x = list(map(int, input().split()))
    if n == 0 and x == 0:
        break
    c = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            ij = i + j
            for k in range(j + 1, n + 1):
                if ij + k == x:
                    c += 1
    print(c)

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 + 1, 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)

-    for i in range(1, n + 1): -        for j in range(i + 1, n + 1): -            ij = i + j +    for i in range(1, min(n + 1, x / 3)): +        for j in range(i + 1, min(n + 1, x / 2)): -                if ij + k == x: +                ijk = i + j + k +                if ijk == x: +                    break +                elif ijk > x: +                    break