#include <iostream>

int main ()
{
	int n, x;
	while (true) {
		std::cin >> n >> x;
		if (n==0 && x==0) break;
		
		int count = 0;
		for (int a=1; a<=n; a++) {
			for (int b=a+1; b<=n; b++) {
				int c = x-a-b;
				if (b < c && c <= n) count++;
				
			}
		}
		
		std::cout << count << std::endl;
	}
	
	return 0;
}


