import std.stdio,
       std.string,
       std.range,
       std.algorithm;

void main(){
	int n, x, cnt;

	while (true){
		scanf("%d %d", &n, &x);

		if (n == 0 && x == 0) break;

		cnt = 0;
		n+=1;

		foreach (i; 1..n){
		foreach (j; i..n){
		foreach (k; j..n){
			if (i == j || i == k || j == k) continue;
			if (i+j+k == x)	cnt++;
		}
		}
		}
		writeln(cnt);
	}
}