function Main(input) {
let dataset = input.split('\n');
let nx = [];
let n, x
for (let i = 0; i < dataset.length; i++){
nx = dataset[i].split(' ').map(Number);
n = nx[0]
x = nx[1]

let count = 0;
if (n === 0 && x === 0) {
break;
} else {
for (let j = 1; j < n; j++){
for (let k = j + 1; k < n; k++){
for (let l = k + 1; l <= n; l++ ){
if ((l + k + j) === x) {
count++;
} else {

}
}
}
}
console.log(count);
}
}
}

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

