function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var K = parseInt(line[0]);
    var S = parseInt(line[1]);
    var roop = Math.min(K,S);
    var ans =0;
    for(var A=0;A<=roop;A++){
        if(S-K-A>=0 && 2*K-S+A+1>0){
                ans += 2*K-S+A+1;
        }
        else if(S-K-A<0 && S-A+1>0){
                ans += S-A+1;
        }
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));