import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
import std.array;
import std.math;
import std.range;

void main()
{
    foreach(line; stdin.byLine)
    {
        auto nn = line.chomp.split.map!(to!uint).array,
             n = nn[0], x = nn[1];

        if(nn == [0, 0]) return;

        uint cnt;
        foreach(a; 1 .. n+1)
            foreach(b; a+1 .. n+1)
                foreach(c; b+1 .. n+1)
                    if(a+b+c == x) ++cnt;

        writeln(cnt);
    }
}