import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
 
    while(kbd.hasNext()){
        int n = kbd.nextInt();
        int x = kbd.nextInt();
        int z=0;
        if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        }
    }
    }
    static boolean m(int a, int b, int c, int x){
    boolean p = a+b+c==x;
    boolean q = a<b && b<c;
    return p&&q;
    }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz