'use strict';
(function(stdin) {
  var lines = stdin.toString();
  var result = (function(data) {
    return data.map(function(v) {
      var param = v.split(' ').map(Number);
      var count = 0;
      for (var i = 1; i < param[0] + 1; i++) {
        for (var j = i + 1; j < param[0] + 1; j++) {
          for (var k = j + 1; k < param[0] + 1; k++) {
            if (i + j + k === param[1]) {
              count++;
            }
          } 
        }
      }
      return count;
    }).join('\n');

  }(
    lines.split('0 0')[0].trim().split('\n')
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));