'use strict';
(function(stdin) {
  //declare function
  function countSumX(array) {
    var n = array[0];
    var x = array[1];
    var result = 0;
    for (var max = n; max > parseInt(x / 3); max--) {
      for (var min = 1; min < max - 1; min++) {
        var mid = x - max - min;
        if (mid > min && mid < max) {
          result += 1;
        }
      }
    }
    return result;
  }
  //declare variable
  var inputs = stdin.toString().trim().split('\n');
  var cloneInputs = inputs.slice(0, inputs.indexOf('0 0'));
  cloneInputs = cloneInputs.map(function(v) {
    return v.split(' ').map(Number);
  });
  //main
  console.log(cloneInputs.map(countSumX).join('\n'));

  //display
  // console.log(cloneInputs);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));