CodeEff/ECCO huggingface dataset:
# Original solution
num_list = []
while True:
    values = [int(x) for x in input().split()]
    if 0 == values[0] and 0 == values[1]:
        break
    num_list.append(values)

for n, t in num_list:
    ret = ' '.join(str(x + y + z) for x in range(1, n + 1) for y in range(x + 1, n + 1) for z in range(y + 1, n + 1))
    cnt = 0
    for x in ret.split():
        if str(t) == x:
            cnt += 1
    print(cnt)

# Optimized solution
num_list = []
while True:
    values = [int(x) for x in input().split()]
    if 0 == values[0] and 0 == values[1]:
        break
    num_list.append(values)

for n, t in num_list:
    ret = ' '.join(str(x + y + z) for x in range(1, n + 1) for y in range(x + 1, n + 1) for z in range(y + 1, n + 1) if t == x + y + z)
    print((ret.count(str(t))))
# Original solution
while True:
    n, x = list(map(int, input().split()))
    count = 0
    if not(n or x):
        break
    for i in range(1, n-1, 1):
        for j in range(i+1, n, 1):
            for k in range(j+1, n+1, 1):
                if i + j + k == x:
                    count += 1
    print(count)

# Optimized solution
while True:
    n, x = list(map(int, input().split()))
    count = 0
    if not(n or x):
        break
    for i in range(1, n-1, 1):
        for j in range(i+1, n, 1):
            k = x - i -j
            if k > j and k <= n:
                count += 1
    print(count)
# Original solution
combNum = [0]*10000
inNum = 0
while True:
    n,x = list(map(int, input().split()))
    calcResult = 0
    numList1 = list(range(1,n+1,1))
    numList2 = list(range(1,n+1,1))
    numList3 = list(range(1,n+1,1))
    if n is x is 0:
        break
    else:
        
        for index1 in range(n):
            for index2 in range(n):
                for index3 in range(n):
                    #index = [numList1[index1], numList2[index2], numList3[index3]]
                    if numList1[index1] is numList2[index2] or numList1[index1] is numList3[index3] or numList2[index2] is numList3[index3] or numList1[index1] is numList2[index2] is numList3[index3]:
                    #if index.count(numList1[index1])>1 or index.count(numList1[index2])>1 or index.count(numList1[index3])>1:
                        pass                
                    else:
                        if numList1[index1]<numList2[index2]<numList3[index3]:
                            calcResult = numList1[index1] + numList2[index2]+numList3[index3]
                            if calcResult == x:
                                combNum[inNum] =combNum[inNum]+1
                                
                        else:
                            pass
        inNum = inNum+1
for index in range(inNum):
    print((combNum[index]))


# Optimized solution
dataNum = 0
combNum = [0] * 100
while True:
    n,x=list(map(int, input().split()))
    if n is x is 0:
        break
    else:
        for a in range(1,n-1):
            for b in range(a+1,n):
                for c in range(b+1,n+1):
                    calcResult = a + b + c
                    if calcResult == x:
                        combNum[dataNum] += 1
                    else:
                        pass
    dataNum += 1

for index in range(dataNum):
    print((combNum[index]))
# Original solution
while True:
    num = list(map(int,input().split()))
    if(num[0] == 0 and num[1] == 0): break
    c = 0
    for i in range(1,num[0] - 1):
        for j in range(i+1,num[0]):
            for k in range(j+1,num[0]+1):
                if(i+j+k == num[1]): c += 1
    
    print(c)


# Optimized solution
while True:
    num = list(map(int,input().split()))
    if(num[0] == 0 and num[1] == 0): break
    c = 0
    for i in range(1,num[0]+1):
        for j in range(i+1,num[0]+1):
            if j <= i:
                continue
            k = num[1]-(i+j)
            if k > j and k <= num[0]:
                c+= 1
    print(c)
# Original solution
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)))



# Optimized solution
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)
# Original solution
from itertools import combinations
while  True:
    n, x = [int(i) for i in input().split()]
    if n == x == 0: break
    count = 0
    array = set(range(1, n+1))
    for ele in combinations(array, 3):
        if sum(ele) == x:
            count += 1
    print(count)

# Optimized solution
while True:
    n,x = [int(i) for i in input().split()]
    if n == 0 and x == 0: break
    count = 0
    # 3????????°?????????????°????x//3?????????x//3 * 3 == x ?????????????°????x//3??\?????§?????????????????????
    for a in range(1, x//3):
        # 3????????°?????????????????????x//2?????????x//2 * 2 == x ?????????????????????x//2??\?????§?????????????????????
        for b in range(a+1,x//2):
            c = x - (a + b)
            if b < c <= n:
                count += 1
    print(count)
# Original solution
import itertools
while True:
    n,x = [int(x) for x in input().split()]
    if (n,x)==(0,0): break
    cnt=0
    for comb in itertools.combinations(list(range(1,n+1)),3):
        if sum(comb) == x: cnt+=1
    print(cnt)

# Optimized solution
while True:
    n,x = [int(x) for x in input().split()]
    if (n,x)==(0,0): break
    cnt=0
    if 3*(n-1) >= x:     # If n-2 + n-1 + n < x, there is no combination
        a_max = x//3 - 1 # a_max + a_max+1 + a_max+2 = x
        if 2*n-1 < x: 
            a_min = x - (2*n-1) # set minimum value of a
        else:
            a_min = 1
        for a in range(a_min,a_max+1):
            b_max = (x-a-1)//2 # b_max + b_max+1 <= x-a
            b_min = (x-a) - n  # set minimum value of b
            b_min = b_min if b_min > a+1 else a+1
            cnt += b_max - b_min + 1
    print(cnt)
# Original solution
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break

    comb = set()
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                if i == j or j == k or i == k:
                    continue
                elif i + j + k == x:
                    sort_9 = sorted((i, j, k))
                    sort_9 = tuple(sort_9)
                    comb.add(sort_9)
    print((len(comb)))



# Optimized solution
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break

    comb = set()
    for i in range(1, n+1):
        for j in range(2, n+1):
            for k in range(3, n+1):
                if i == j or j == k or i == k:
                    continue
                elif i + j + k == x:
                    sort_9 = sorted((i, j, k))
                    comb.add(tuple(sort_9))

    print((len(comb)))
# Original solution
import sys

while True:
	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == n and 0 == x:
		break
		
	cnt = 0
	goto = False
	for i in range( 1, n-1 ):
		if  x < 3*(i+1):
			break
		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:
					goto = True
					break
			goto = False
	
	print( cnt )

# Optimized solution
import sys

while True:
	n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
	if 0 == n and 0 == x:
		break
		
	cnt = 0
	for i in range( 1, n-1 ):
		if  x < 3*(i+1):
			break
		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 )
# Original solution
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 )

# Optimized solution
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 )
# Original solution
while True:
	k=list(map(int,input().split(" ")))
	if k[0]==k[1]==0:
		break
	ct=0
	a=0
	b=0
	c=0	
	max=k[0]
	sum=k[1]
	a=max+1
	
	while True:
		a-=1
		b=a-1
		c=sum-a-b
		if not a>b>c:
			print(ct)
			break
		while a>b>c:
			if a>b>c>0:
				ct+=1
			b-=1
			c+=1
			

# Optimized solution
while True:
	k=list(map(int,input().split(" ")))
	if k[0]==k[1]==0:
		break
	ct=0
	a=0
	b=0
	c=0	
	max=k[0]
	sum=k[1]
	a=max+1
	while True:
		a-=1
		b=a-1
		c=sum-a-b
		if not a>c:
			print(ct)
			break
		while b>c:
			if c>0:
				ct+=1
			b-=1
			c+=1
# Original solution
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)

# Optimized solution
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 == s+m+e:
                    count += 1

    print(count)
# Original solution

while True:
	arr = list(map(int, input().split()))
	n = arr[0]
	x = arr[1]

	if n == 0 and x == 0:
		break
	c = 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:
					c += 1
	print(c)
	c = 0



# Optimized solution

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)
# Original solution
while True:
    (n, x) =  [int(i) for i in input().split()]
    if n == x == 0:
        break

    count = 0
    for a in range(1, n+1):
        for b in range(a+1, n+1):
            for c in range(b+1, n+1):
                if (a + b + c) == x:
                    count += 1
    print(count)

# Optimized solution
while True:
    (n, x) =  [int(i) for i in input().split()]
    if n == x == 0:
        break

    count = 0
    for a in range(1, n+1):
        for b in range(a+1, n+1):
            for c in range(b+1, n+1):
                if (a + b + c) == x:
                    count += 1
                elif (a + b + c) > x:
                    break
    print(count)
# Original solution
count_a = []
pos = 0
while True:
    n, x = list(map(int, input().split()))
    count = 0
    if n == x == 0:
        break
    else:
        for i in range(1, (n+1)):
            for j in range(1, (n+1)):
                for k in range(1, (n+1)):
                    if (i != j) and (j != k) and (i != k):
                        if (i+j+k) == x:
                            count += 1
        count_a.append(int(count/6))
        pos = pos+1

for i  in count_a:
    print(i)


# Optimized solution
count_a = []
pos = 0
while True:
    n, x = list(map(int, input().split()))
    count = 0
    if n == x == 0:
        break
    else:
        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) and (j != k) and (i != k):
                        if (i+j+k) == x:
                            count += 1
        count_a.append(count)
        pos = pos+1

for i  in count_a:
    print(i)
# Original solution
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    y = 0
    for i in range(1, n + 1):
        for j in range(1, n + 1):
                for k in range(1, n + 1):
                    if i != j != k != i and i + j + k == x:
                        y += 1
    print((y // 6))

# Optimized solution
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    y = 0
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            if i == j:
                continue
            for k in range(1, n + 1):
                if j == k or k == i:
                    continue
                elif i + j + k == x:
                    y += 1
    print((y // 6))
# Original solution
while(1):
    comb = []
    count =0
    inp = input().split(" ")
    if inp[0] == "0" and inp[1] == "0":
        break
    for i in range(1,int(inp[0])+1):
        for j in range(1,int(inp[0])+1):
            if i == j:
                break
            sum = i + j
            if sum > int(inp[1]):
                j = int(inp[0])
                break
            for k in range(1,int(inp[0])+1):
                if i == j or i == k or j == k:
                    break
                sum = i + j + k
                if sum > int(inp[1]):
                    k = int(inp[0])
                    break
                if sum == int(inp[1]):
                    if not ([i,j,k] in comb or [i,k,j] in comb or [j,k,i] in comb or [j,i,k] in comb or [k,i,j]  in comb or [k,j,i] in comb):
                        comb.append([i,j,k])
                        count += 1
    print(count)


# Optimized solution
# coding: UTF-8
def find_comb(n,x):
    count = 0
    #探索
    for i in range(1,n-1):
        for j in range(i+1,n):
            k = x - i - j #←がi < j < k <= nを満たせばその時点で総和がxとなる
            if  j < k <= n:
                count += 1
    print(count)
while(1):
    n,x = list(map(int, input().split(" ")))
    if(n == 0 and x == 0):
        break
    find_comb(n,x)
# Original solution
while True:
    n,x= list(map(int,input().split()))

    if n == x == 0:
        break

    count = 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 :
                    count = count + 1
    print(count)

# Optimized solution
while True:
    n,x= list(map(int,input().split()))

    if n == x == 0:
        break

    count = 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:
                     count = count + 1
                     break
    print(count)
# Original solution
while True:
    n,x= list(map(int,input().split()))

    if n == x == 0:
        break

    count = 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:
                     count = count + 1
                     break
    print(count)

# Optimized solution
while True:
    n,x= list(map(int,input().split()))

    if n == x == 0:
        break

    count = 0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i + j + k == x:
                     count = count + 1
                     break
    print(count)
# Original solution
from itertools import combinations

if __name__ == '__main__':
    while True:
        # ?????????????????\???
        data = [int(x) for x in input().split(' ')]
        upper_limit = data[0]
        target_number = data[1]
        if upper_limit == 0 and target_number == 0:
            break

        # ????????????????????????
        choices = combinations(list(range(1, upper_limit+1)), 3)

        # ????¨???????X????????´????????°????¢????????????????
        hit_count = 0
        for c in choices:
            # print(c)
            if sum(c) == target_number:
                hit_count += 1
        print(hit_count)

# Optimized solution
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=jp

"""
import sys
from sys import stdin
from itertools import combinations
input = stdin.readline


def main(args):
    while True:
        n, x = list(map(int, input().split()))
        if n == 0 and x == 0:
            break

        ans = 0
        for c in combinations(list(range(1, n+1)), 3):
            if sum(c) == x:
                ans += 1

        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
# Original solution
while True:
    n, x = list(map(int, input().split()))
    if n == 0:
        break

    count = 0
    for n1 in range(1, n+1):
        for n2 in range(n1+1, n+1):
            for n3 in range(n2+1, n+1):
                if n1 + n2 + n3 == x:
                    count += 1

    print(count)

# Optimized solution
while True:
    n, x = list(map(int, input().split()))
    if n == 0 and x == 0:
        break

    count = 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 + k + j == x:
                    count += 1
    print(count)
# Original solution
n,x = -1,-1
table = []
while n != 0 or x != 0:
  n,x = (int(x) for x in input().split())
  table.append([n,x])

for t in table:
  n = t[0]
  x = t[1]
  if n == 0 and x == 0:
    break
  i = 1
  s = 0
  while i < n:
    if x - i > n + (n - 1):
      continue
    else:
      j = i + 1
      while j < n:
        if x - i - j <= n and x - i - j > j:
#          print (str(i) + "," + str(j) + "," + str(x - i - j))
          s += 1
        j += 1
    i += 1
  print (s)


# Optimized solution
n,x = -1,-1
table = []
while n != 0 or x != 0:
  n,x = (int(x) for x in input().split())
  table.append([n,x])

for t in table:
  n = t[0]
  x = t[1]
  if n == 0 and x == 0:
    break
  i = 1
  s = 0
  while i < n:
    #print (i)
    if x - i > n + (n - 1):
      i += 1
      continue
    else:
      j = i + 1
      while j < n:
        #print (str(i) + "," + str(j) + "," + str(x - i - j))
        if x - i - j <= n and x - i - j > j:
          s += 1
        j += 1
      i += 1
  print (s)
# Original solution
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    count = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                if (i != j and i != k and j != k and i < j < k):
                    if i+j+k == x:
                        count += 1
    print(count)

# Optimized solution
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    count = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                if (i < j < k):
                    if i+j+k == x:
                        count += 1
    print(count)
# Original solution
#coding:utf-8
#1_7_B 2015.4.5
while True:
    n,x = list(map(int,input().split()))
    if n == x == 0:
        break
    count = 0
    
    for i in range(1 , n + 1):
        for j in range(1 , n + 1):
            for k in range(1 , n + 1):
                if i + j + k == x and i < j < k:
                    count += 1
    print(count)

# Optimized solution
#coding:utf-8
#1_7_B 2015.4.5
while True:
    n,x = list(map(int,input().split()))
    if n == x == 0:
        break
    count = 0
    
    for i in range(1 , n + 1):
        for j in range(1 , n + 1):
            if (x - i - j) <= n and i < j < (x - i -j):
                count += 1
    print(count)
# Original solution
#coding:utf-8
#1_7_B 2015.4.5
while True:
    n,x = list(map(int,input().split()))
    if n == x == 0:
        break
    count = 0
    
    for i in range(1 , n + 1):
        for j in range(1 , n + 1):
            if (x - i - j) <= n and i < j < (x - i -j):
                count += 1
    print(count)

# Optimized solution
#coding:utf-8
#1_7_B 2015.4.5
while True:
    n,x = list(map(int,input().split()))
    if n == x == 0:
        break
    count = 0
    
    for i in range(1 , n + 1):
        for j in range(1 , n + 1):
            if i < j < (x - i - j) <= n:
                count += 1
    print(count)
# Original solution
ret = []
while True:
   n, x = list(map(int, input().split()))
   num_arr = [i for i in range(1, n+1)]
   if (n, x) == (0, 0):
       break

   cnt = 0
   for i in range(n, 0, -1):
       if x - i <= 2:
           continue
       #print "i : %d" % i
       for j in range(i -1, 0, -1):
          if x-i-j <= 0:
              continue
          #print "j : %d" % j
          for k in range(j - 1, 0 , -1):
              if x-i-j-k < 0:
                  continue
              if x -i-j-k == 0:
                  cnt += 1
                  #print "k : %d" % k
                  break
   ret += [cnt]
for i in ret:
    print(i)

# Optimized solution
ret = []
while True:
   n, x = list(map(int, input().split()))
   num_arr = [i for i in range(1, n+1)]
   if (n, x) == (0, 0):
       break

   cnt = 0
   for i in range(n, 0, -1):
       for j in range(i -1, 0, -1):
           if 0 < x - i - j < j:
               cnt += 1
          
   ret += [cnt]
for i in ret:
    print(i)
# Original solution
def solve(sup,rest,digit,used1,used2):
    if digit==0:
        if rest==0:
            return 1
        else:
            return 0
    sum=0
    for i in range(1,sup+1):
        if i!=used1 and i!=used2:
            if used1==0:
                sum+=solve(sup,rest-i,digit-1,i,used2)
            elif used2==0:
                sum+=solve(sup,rest-i,digit-1,used1,i)
            else:
                sum+=solve(sup,rest-i,digit-1,used1,used2)
    return sum

N=[]
X=[]
while True:
    n,x=list(map(int,input().split()))
    if (n,x)==(0,0):
        break
    N.append(n)
    X.append(x)
for i in range(len(N)):
    print(('%d'%(solve(N[i],X[i],3,0,0)/6)))

# Optimized solution
def solve(sup,rest,digit,used1,used2):
    if rest<0:
        return 0
    if digit==0:
        if rest==0:
            return 1
        else:
            return 0
    sum=0
    for i in range(1,sup+1):
        if i!=used1 and i!=used2:
            if used1==0:
                sum+=solve(sup,rest-i,digit-1,i,used2)
            elif used2==0:
                sum+=solve(sup,rest-i,digit-1,used1,i)
            else:
                sum+=solve(sup,rest-i,digit-1,used1,used2)
    return sum

N=[]
X=[]
while True:
    n,x=list(map(int,input().split()))
    if (n,x)==(0,0):
        break
    N.append(n)
    X.append(x)
for i in range(len(N)):
    print(('%d'%(solve(N[i],X[i],3,0,0)/6)))
# Original solution
def dfs(i, j, s):
    if j > 3:
        return
    if j == 3 and s == x:
        ans.append(1)

    for k in range(1, i):
        dfs(k, j + 1, s + k)

while True:
    ans = []
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break

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

    print((sum(ans)))


# Optimized solution
def dfs(i, j, s):
    if j > 3:
        return
    if j == 3 and s == x:
        ans.append(1)

    for k in range(1, i):
        if s + k > x:
            break
        dfs(k, j + 1, s + k)

while True:
    ans = []
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break

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

    print((sum(ans)))
# Original solution
def dfs(i, j, s):
    if j > 3:
        return
    if j == 3 and s == x:
        ans.append(1)

    for k in range(1, i):
        if s + k > x:
            break
        dfs(k, j + 1, s + k)

while True:
    ans = []
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break

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

    print((sum(ans)))


# Optimized solution
def calc(n, x):
    result = 0
    for i in range(3, n + 1):
        for j in range(2, i):
            for k in range(1, j):
                if sum([i, j, k]) == x:
                    result += 1
    return str(result)

ans = []
while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break
    ans.append(calc(n, x))

print(("\n".join(ans)))