function main(input) {
  var temp = input.split('\n');
  for (var i = 0; i < temp.length; i++) {
    var temp2 = temp[i].split(' ').map(Number);
    var limit = temp2[0];
    var target = temp2[1];
    if (!limit && !target)
      break;
    var count = 0;
    for (var j = 1; j < limit - 1; j++) {
      for (var k = j + 1; k < limit; k++) {
        for (var l = k + 1; l < limit + 1; l++) {
          if ((j + k + l) == target) {
            count++;
          }
        }
      }
    }
    console.log(count)
  }
}

var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
main(x);
