import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder str = new StringBuilder();

		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			int num = 0;
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				}
			}
			if (n == 0 && x == 0)
				break;
			str.append(num + "\n");

		}
		System.out.print(str);

	}

} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder str = new StringBuilder();

		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			int num = 0;
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				}
			}
			if (n == 0 && x == 0)
				break;
			str.append(num + "\n");

		}
		System.out.print(str);

	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder str = new StringBuilder();

		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			int num = 0;
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				}
			}
			if (n == 0 && x == 0)
				break;
			str.append(num + "\n");

		}
		System.out.print(str);

	} main {
		Scanner scan = new Scanner(System.in);
		StringBuilder str = new StringBuilder();

		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			int num = 0;
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				}
			}
			if (n == 0 && x == 0)
				break;
			str.append(num + "\n");

		}
		System.out.print(str);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) StringBuilder str = new StringBuilder(); str new StringBuilder() while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			int num = 0;
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				}
			}
			if (n == 0 && x == 0)
				break;
			str.append(num + "\n");

		} true {
			int n = scan.nextInt();
			int x = scan.nextInt();
			int num = 0;
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				}
			}
			if (n == 0 && x == 0)
				break;
			str.append(num + "\n");

		} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan int num = 0; num 0 for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				}
			} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				}
			} {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				}
			} for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				} int j = i + 1; int j = i + 1; j i + 1 i 1 j <= n j n j++ j++ j {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				} {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				} for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					} int k = j + 1; int k = j + 1; k j + 1 j 1 k <= n k n k++ k++ k {
						if (i + j + k == x)
							num++;
					} {
						if (i + j + k == x)
							num++;
					} if (i + j + k == x)
							num++; i + j + k == x i + j + k i + j + k i j k x num++ num if (n == 0 && x == 0)
				break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; str.append(num + "\n") str.append str num + "\n" num "\n" System.out.print(str) System.out.print System.out System System.out str String[] args args
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder str = new StringBuilder();

		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			int num = 0;
			for (int i = 1; i <= n; i++) {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							num++;
					}
				}
			}
			if (n == 0 && x == 0)
				break;
			str.append(num + "\n");

		}
		System.out.print(str);

	}

}