import sys



while True:

	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]

	if 0 == n and 0 == x:

		break

		

	cnt = 0

	ave = x // 3

	for i in range( 1, ave ):

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

			if  x <= ( i+j ):

				break

			for k in range( j+1, n+1 ):

				s = ( i + j + k )

				if x == s:

					cnt += 1

					break

				elif   x < s:

					break

	

	print( cnt )
import sys



while True:

	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]

	if 0 == n and 0 == x:

		break

		

	cnt = 0

	ave = x // 3

	for i in range( 1, ave ):

		ave2 = (x-i) // 2

		for j in range( i+1, ave2+1 ):

			k = x-i-j

			if j < k and k <= n:

				cnt += 1

	

	print( cnt )
import sys

while True:
    n, x = [int(val) for val in sys.stdin.readline().split(" ")]
    if 0 == n and 0 == x:
        break
    cnt = 0
    ave = x // 3
    for i in range(1, ave):
        for j in range(i + 1, n):
            if x <= (i + j):
                break
            for k in range(j + 1, n + 1):
                s = i + j + k
                if x == s:
                    cnt += 1
                    break
                elif x < s:
                    break
    print(cnt)

import sys

while True:
    n, x = [int(val) for val in sys.stdin.readline().split(" ")]
    if 0 == n and 0 == x:
        break
    cnt = 0
    ave = x // 3
    for i in range(1, ave):
        ave2 = (x - i) // 2
        for j in range(i + 1, ave2 + 1):
            k = x - i - j
            if j < k and k <= n:
                cnt += 1
    print(cnt)

-        for j in range(i + 1, n): -            if x <= (i + j): -                break -            for k in range(j + 1, n + 1): -                s = i + j + k -                if x == s: -                    cnt += 1 -                    break -                elif x < s: -                    break +        ave2 = (x - i) // 2 +        for j in range(i + 1, ave2 + 1): +            k = x - i - j +            if j < k and k <= n: +                cnt += 1