//HowManyWays? ???????????°????????????????????§???
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int n,x,i,j,k,num;	//num????????????????????????????????????????????°???????´????????????°
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		x = in.nextInt();
		
		while(n != 0){
			num =0;
			
			//????????§????????????????????????????????????
			for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			}
			
			System.out.println(num/6);	//3! = 6??????????????????????????§6??§??????
			n = in.nextInt();
			x = in.nextInt();
		}
		
		in.close();
	}
}
/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