var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var row = input.split('\n');
for(var i=0;i<row.length;i++){
    var number = row[i].split(' ').map(Number);
    var n = number[0];
    var x = number[1];
    if(n === 0 && x === 0){
        break;
    }
    var result = 0;
    for(var j=1;j<=n;j++){
        for(var k=j+1;k<=n;k++){
            if(j+k >= x){
                break;
            }
            var l = x-(j+k);
            if(l>k && l<=n){
                result++;
            }
        }
    }
console.log(result);
}
