function Main(input) {
    input = input.split("\n");
    for (i=0; i<input.length; i++) {
        tmp = input[i].split(" ")
        var n = parseInt(tmp[0])
        var x = parseInt(tmp[1])
        var num = 0
        if (n === 0 && x === 0) {
            break;
        }
        for (j=1; j <= n-2; j++) {
            for (k=j+1; k<=n-1; k++) {
                for (l=k+1; l<= n; l++) {
                    if (j + k + l === x) {
                        num += 1
                    }
                }
            }
        }
        console.log(num)
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
