import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = new String[2];
		int in[] = new int[2];
		int cnt;
		while(true){
			str = br.readLine().split(" ");
			in = parseInts(str);
			if(in[0]==0 && in[1]==0) break;
			cnt = 0;
			for(int n=1; n<in[0]-1; n++){
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			}
			System.out.println(cnt);
		}
	}
	static int[] parseInts(String[] s){
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	}
}
/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