let input = require('fs').readFileSync('/dev/stdin', 'UTF-8');
let arr = input.split('\n');

for (let I = 0; I < arr.length; I++) {
  let n = arr[I].split(' ').map(Number)[0]
  let x = arr[I].split(' ').map(Number)[1]
  if (n === 0 && x === 0) break;
  let cnt= 0;
  for (let i = 1; i <= n; i++) {
    for (let j = i + 1; j <= n; j++) {
      if (i + j >= x) break;
      let k = x - (i + j);
      if (k > j && k <= n) cnt++;
    }
  }
  console.log(cnt)
}
