import std.stdio, std.string, std.array, std.conv;

void main() {
    while (true) {
        int[] tmp = readln.chomp.split.to!(int[]);
        int n = tmp[0], x = tmp[1];
        int cnt = 0;
        if (n == 0 && x == 0) break;
        foreach (i; 1 .. n+1) {
            foreach (j; 1 .. i) {
                foreach (k; 1 .. j) {
                    if (i + j + k == x && i != j && j != k && k != i) ++cnt;
                }
            }
        }
        cnt.writeln;
    }
}
