import itertools

while True:

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

    if n == x == 0:

        break

    ans = 0

    for t in list(itertools.combinations([i + 1 for i in range(n)], 3)):

        if sum(t) == x:

            ans += 1

    print(ans)
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B "How many ways?" ????§£??????

# 

import itertools

while True:

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

    if not n:

        break

    print((list(map(sum, itertools.combinations(list(range(1, n + 1)), 3))).count(x)))
import itertools

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

# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B "How many ways?" ????§£??????
#
import itertools

while True:
    n, x = list(map(int, input().split()))
    if not n:
        break
    print((list(map(sum, itertools.combinations(list(range(1, n + 1)), 3))).count(x)))

+# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B "How many ways?" ????§£?????? +# -    if n == x == 0: +    if not n: -    ans = 0 -    for t in list(itertools.combinations([i + 1 for i in range(n)], 3)): -        if sum(t) == x: -            ans += 1 -    print(ans) +    print((list(map(sum, itertools.combinations(list(range(1, n + 1)), 3))).count(x)))