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



while n != 0 or x != 0:

	cnt = 0

	i = 1

	while i <= n - 2:

		j = i + 1

	#	if i >= x:

	#		break

		while j <= n - 1:

			k = j + 1

	#		if i + j >= x:

	#			break

			while k <= n:

	#			if i + j + k > x:

	#				break

				if i + j + k == x:

					cnt += 1

				k += 1

			j += 1

		i += 1

	print(cnt)

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

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



while n != 0 or x != 0:

	cnt = 0

	i = 1

	while i <= n - 2:

		j = i + 1

		if i >= x:

			break

		while j <= n - 1:

			k = j + 1

			if i + j >= x:

				break

			while k <= n:

				if i + j + k > x:

					break

				if i + j + k == x:

					cnt += 1

				k += 1

			j += 1

		i += 1

	print(cnt)

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

n, x = list(map(int, input().split()))
while n != 0 or x != 0:
    cnt = 0
    i = 1
    while i <= n - 2:
        j = i + 1
        # 	if i >= x:
        # 		break
        while j <= n - 1:
            k = j + 1
            # 		if i + j >= x:
            # 			break
            while k <= n:
                # 			if i + j + k > x:
                # 				break
                if i + j + k == x:
                    cnt += 1
                k += 1
            j += 1
        i += 1
    print(cnt)
    n, x = list(map(int, input().split()))

n, x = list(map(int, input().split()))
while n != 0 or x != 0:
    cnt = 0
    i = 1
    while i <= n - 2:
        j = i + 1
        if i >= x:
            break
        while j <= n - 1:
            k = j + 1
            if i + j >= x:
                break
            while k <= n:
                if i + j + k > x:
                    break
                if i + j + k == x:
                    cnt += 1
                k += 1
            j += 1
        i += 1
    print(cnt)
    n, x = list(map(int, input().split()))

-        # 	if i >= x: -        # 		break +        if i >= x: +            break -            # 		if i + j >= x: -            # 			break +            if i + j >= x: +                break -                # 			if i + j + k > x: -                # 				break +                if i + j + k > x: +                    break