import std.stdio;

void main() {
	for (;;) {
		int n, x;
		"%d %d\n".readf(&n, &x);
		if (n == 0 && x == 0) break;
		
		int c = 0;
		foreach (i; 1..n-1) {
			foreach (j; i+1..n) {
				foreach (k; j+1..n+1) {
					if (i+j+k == x) ++c;
				}
			}
		}
		c.writeln;
	}
}