def dfs(i, j, s):

    if j > 3:

        return

    if j == 3 and s == x:

        ans.append(1)



    for k in range(1, i):

        if s + k > x:

            break

        dfs(k, j + 1, s + k)



while True:

    ans = []

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

    if n == x == 0:

        break



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

        dfs(i, 1, i)



    print((sum(ans)))

def calc(n, x):

    result = 0

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

        for j in range(2, i):

            for k in range(1, j):

                if sum([i, j, k]) == x:

                    result += 1

    return str(result)



ans = []

while True:

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

    if n == x == 0:

        break

    ans.append(calc(n, x))



print(("\n".join(ans)))

def dfs(i, j, s):
    if j > 3:
        return
    if j == 3 and s == x:
        ans.append(1)
    for k in range(1, i):
        if s + k > x:
            break
        dfs(k, j + 1, s + k)


while True:
    ans = []
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    for i in range(3, n + 1):
        dfs(i, 1, i)
    print((sum(ans)))

def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            for k in range(1, j):
                if sum([i, j, k]) == x:
                    result += 1
    return str(result)


ans = []
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    ans.append(calc(n, x))
print(("\n".join(ans)))

-def dfs(i, j, s): -    if j > 3: -        return -    if j == 3 and s == x: -        ans.append(1) -    for k in range(1, i): -        if s + k > x: -            break -        dfs(k, j + 1, s + k) +def calc(n, x): +    result = 0 +    for i in range(3, n + 1): +        for j in range(2, i): +            for k in range(1, j): +                if sum([i, j, k]) == x: +                    result += 1 +    return str(result) +ans = [] -    ans = [] -    for i in range(3, n + 1): -        dfs(i, 1, i) -    print((sum(ans))) +    ans.append(calc(n, x)) +print(("\n".join(ans)))