import itertools



while True:

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



	if n == 0 and x == 0:

		break



	#データリスト作成

	data = [m for m in range(1,n+1)]

	data_cmb = list(itertools.combinations(data,3))



	#検証

	res = [ret for ret in data_cmb if sum(ret) == x]

	print((len(res)))



while True:

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



	if n == 0 and x == 0:

		break



	#データリスト作成

	data = [m for m in range(1,n+1)]

	data_list = []

	cnt = 0

	#n種類の数字があって、xになる組み合わせは？

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

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

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

				if i+j+k == x:

					cnt += 1



	print(cnt)



import itertools

while True:
    n, x = list(map(int, input().split(" ")))
    if n == 0 and x == 0:
        break
    # データリスト作成
    data = [m for m in range(1, n + 1)]
    data_cmb = list(itertools.combinations(data, 3))
    # 検証
    res = [ret for ret in data_cmb if sum(ret) == x]
    print((len(res)))

while True:
    n, x = list(map(int, input().split(" ")))
    if n == 0 and x == 0:
        break
    # データリスト作成
    data = [m for m in range(1, n + 1)]
    data_list = []
    cnt = 0
    # n種類の数字があって、xになる組み合わせは？
    for i in range(1, n + 1):
        for j in range(1 + i, n + 1):
            for k in range(1 + j, n + 1):
                if i + j + k == x:
                    cnt += 1
    print(cnt)

-import itertools - -    data_cmb = list(itertools.combinations(data, 3)) -    # 検証 -    res = [ret for ret in data_cmb if sum(ret) == x] -    print((len(res))) +    data_list = [] +    cnt = 0 +    # n種類の数字があって、xになる組み合わせは？ +    for i in range(1, n + 1): +        for j in range(1 + i, n + 1): +            for k in range(1 + j, n + 1): +                if i + j + k == x: +                    cnt += 1 +    print(cnt)