Write a program which identifies the number of combinations of three integers which satisfy the following conditions:    * You should select three distinct integers from 1 to n.   * A total sum of the three integers is x.  For example, there are two combinations for n = 5 and x = 9.    * 1 + 3 + 5 = 9   * 2 + 3 + 4 = 9
n, x = [int(i) for i in input().split()]

count = 0
for s in range(1, n // 2 + 1):
    for e in range(n, n // 2, -1):
        m = x - s - e
        if m != s and m != e and m > e and m  <= n:
            print(s, m, e)
            count += 1

    print(count)
while True:
    n,x = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    for s in range(1, n-1):
        for m in range(s+1, n):
            for e in range(m+1,n+1):
                if x == sum([s,m,e]):
                    count += 1
 
    print(count)