

while True:

	arr = list(map(int, input().split()))

	n = arr[0]

	x = arr[1]



	if n == 0 and x == 0:

		break

	ans = 0

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

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

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

				if i + j + k == x:

					ans += 1

	print(ans)





def subset_sum(n,a,s):

	cnt=0

	for i in range(n):

		r=s-a[i]

		j=i+1

		k=n-1

		while j<k:

			t=a[j]+a[k]

			if t<r:

				j+=1

			elif t>r:

				k-=1

			else:

				cnt+=1

				j+=1

				k-=1

	return cnt



while True:

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

	if n==0 and s==0:

		break

	a=[0]*n

	for i in range(n):

		a[i]=i+1

	print((subset_sum(n,a,s)))



while True:
    arr = list(map(int, input().split()))
    n = arr[0]
    x = arr[1]
    if n == 0 and x == 0:
        break
    ans = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    ans += 1
    print(ans)

def subset_sum(n, a, s):
    cnt = 0
    for i in range(n):
        r = s - a[i]
        j = i + 1
        k = n - 1
        while j < k:
            t = a[j] + a[k]
            if t < r:
                j += 1
            elif t > r:
                k -= 1
            else:
                cnt += 1
                j += 1
                k -= 1
    return cnt


while True:
    n, s = list(map(int, input().split()))
    if n == 0 and s == 0:
        break
    a = [0] * n
    for i in range(n):
        a[i] = i + 1
    print((subset_sum(n, a, s)))

+def subset_sum(n, a, s): +    cnt = 0 +    for i in range(n): +        r = s - a[i] +        j = i + 1 +        k = n - 1 +        while j < k: +            t = a[j] + a[k] +            if t < r: +                j += 1 +            elif t > r: +                k -= 1 +            else: +                cnt += 1 +                j += 1 +                k -= 1 +    return cnt + + -    arr = list(map(int, input().split())) -    n = arr[0] -    x = arr[1] -    if n == 0 and x == 0: +    n, s = list(map(int, input().split())) +    if n == 0 and s == 0: -    ans = 0 -    for i in range(1, n + 1): -        for j in range(i + 1, n + 1): -            for k in range(j + 1, n + 1): -                if i + j + k == x: -                    ans += 1 -    print(ans) +    a = [0] * n +    for i in range(n): +        a[i] = i + 1 +    print((subset_sum(n, a, s)))