import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		while (true) {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		}
		sc.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