import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//?????±????????????????´?
		ArrayList<String> list = new ArrayList<String>();
		while(true) {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		}
		
		//?????±???int???????????????2?¬?????????????????´???????
		int [][] data = new int[list.size() - 1][2];
		for(int i = 0; i < list.size() - 1; i++) {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		}
		
		//
		int answer = 0;
		for(int cntData = 0; cntData < data.length; cntData++) {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		}
	}

}
/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