while True:

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

    if n == 0:

        break



    count = 0

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

        for n2 in range(n1+1, n+1):

            for n3 in range(n2+1, n+1):

                if n1 + n2 + n3 == x:

                    count += 1



    print(count)
while True:

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

    if n == 0 and x == 0:

        break



    count = 0

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

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

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

                if i + k + j == x:

                    count += 1

    print(count)



while True:
    n, x = list(map(int, input().split()))
    if n == 0:
        break
    count = 0
    for n1 in range(1, n + 1):
        for n2 in range(n1 + 1, n + 1):
            for n3 in range(n2 + 1, n + 1):
                if n1 + n2 + n3 == x:
                    count += 1
    print(count)

while True:
    n, x = list(map(int, input().split()))
    if n == 0 and x == 0:
        break
    count = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i + k + j == x:
                    count += 1
    print(count)

-    if n == 0: +    if n == 0 and x == 0: -    for n1 in range(1, n + 1): -        for n2 in range(n1 + 1, n + 1): -            for n3 in range(n2 + 1, n + 1): -                if n1 + n2 + n3 == x: +    for i in range(1, n + 1): +        for j in range(i + 1, n + 1): +            for k in range(j + 1, n + 1): +                if i + k + j == x: