while(True):

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

    if(n == x == 0):

        break

    ans = 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 + j + k == x):

                    ans += 1

    print(ans)
while(True):

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

    if(n == x == 0):

        break

    ans = 0

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

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

            if(j < x - i - j < n + 1):

                ans += 1

    print(ans)
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    ans = 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 + j + k == x:
                    ans += 1
    print(ans)

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

-            for k in range(j + 1, n + 1): -                if i + j + k == x: -                    ans += 1 +            if j < x - i - j < n + 1: +                ans += 1