function main(input) {
  const args = input.split("\n");

  for (let i = 0; i < args.length; i++) {
    let n, x;
    [n, x] = args[i].split(" ").map((x) => Number(x));
    if (n === 0 && x === 0) {
      break;
    }
    solve(n, x);
  }
}

function solve(n, x) {
  let ans = 0;
  for (let i = 1; i <= n; i++) {
    for (let j = i + 1; j <= n; j++) {
      for (let k = j + 1; k <= n; k++) {
        if (i + j + k == x) {
          ans++;
        }
      }
    }
  }
  console.log(ans);
}

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

