import itertools

while(True):

    n, x = [int(i) for i in input().split()]

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

    cnt = 0

    for li in itertools.combinations(list(range(1, n + 1)),3):

        if sum(li) == x: cnt += 1

    print(cnt)
from itertools import combinations

while True:

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

    if n == x == 0:

        break

    cnt = 0

    for li in combinations(list(range(1, n + 1)), 3):

        if sum(li) == x:

            cnt += 1

    print(cnt)



import itertools

while True:
    n, x = [int(i) for i in input().split()]
    if n == 0 and x == 0:
        break
    cnt = 0
    for li in itertools.combinations(list(range(1, n + 1)), 3):
        if sum(li) == x:
            cnt += 1
    print(cnt)

from itertools import combinations

while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    cnt = 0
    for li in combinations(list(range(1, n + 1)), 3):
        if sum(li) == x:
            cnt += 1
    print(cnt)

-import itertools +from itertools import combinations -    n, x = [int(i) for i in input().split()] -    if n == 0 and x == 0: +    n, x = list(map(int, input().split())) +    if n == x == 0: -    for li in itertools.combinations(list(range(1, n + 1)), 3): +    for li in combinations(list(range(1, n + 1)), 3):