# coding: utf-8

while True:

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

    

    if n == x == 0:

        break

    

    list = [i for i in range(1,n+1)]

    count = 0

    

    for i in list:

        for j in list[i:]:

            k = x - (i + j)

            if list[j:].count(k) == 1:

                count += 1

                

    print(count)
# coding: utf-8

while True:

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

    

    if n == x == 0:

        break



    count = 0

    

    for i in range(1,int(x/3)+1):

        for j in range(i+1,int((x-i)/2)+1):

            k = x - (i + j)

            if j < k <= n:

                count += 1

                

    print(count)
# coding: utf-8
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    list = [i for i in range(1, n + 1)]
    count = 0
    for i in list:
        for j in list[i:]:
            k = x - (i + j)
            if list[j:].count(k) == 1:
                count += 1
    print(count)

# coding: utf-8
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    count = 0
    for i in range(1, int(x / 3) + 1):
        for j in range(i + 1, int((x - i) / 2) + 1):
            k = x - (i + j)
            if j < k <= n:
                count += 1
    print(count)

-    list = [i for i in range(1, n + 1)] -    for i in list: -        for j in list[i:]: +    for i in range(1, int(x / 3) + 1): +        for j in range(i + 1, int((x - i) / 2) + 1): -            if list[j:].count(k) == 1: +            if j < k <= n: