import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int n, x;
		int i = 0, j = 0, k = 0;
		int count = 0;
		Scanner stdIn = new Scanner(System.in);

		boolean flag = true;
		while (flag) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();

			if (n == 0 && x == 0) {
				flag = false;
				break;
			}

			count = 0;
			for (i = 1; i < n; i++) {
				for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				}

			}
			System.out.println(count);
		}
		stdIn.close();
	}
} import java.util.Scanner; Scanner java.util class Main {

	public static void main(String[] args) {

		int n, x;
		int i = 0, j = 0, k = 0;
		int count = 0;
		Scanner stdIn = new Scanner(System.in);

		boolean flag = true;
		while (flag) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();

			if (n == 0 && x == 0) {
				flag = false;
				break;
			}

			count = 0;
			for (i = 1; i < n; i++) {
				for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				}

			}
			System.out.println(count);
		}
		stdIn.close();
	}
} Main public static void main(String[] args) {

		int n, x;
		int i = 0, j = 0, k = 0;
		int count = 0;
		Scanner stdIn = new Scanner(System.in);

		boolean flag = true;
		while (flag) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();

			if (n == 0 && x == 0) {
				flag = false;
				break;
			}

			count = 0;
			for (i = 1; i < n; i++) {
				for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				}

			}
			System.out.println(count);
		}
		stdIn.close();
	} main {

		int n, x;
		int i = 0, j = 0, k = 0;
		int count = 0;
		Scanner stdIn = new Scanner(System.in);

		boolean flag = true;
		while (flag) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();

			if (n == 0 && x == 0) {
				flag = false;
				break;
			}

			count = 0;
			for (i = 1; i < n; i++) {
				for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				}

			}
			System.out.println(count);
		}
		stdIn.close();
	} int n n x; x int i = 0 i 0 j = 0 j 0 k = 0; k 0 int count = 0; count 0 Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) boolean flag = true; flag true while (flag) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();

			if (n == 0 && x == 0) {
				flag = false;
				break;
			}

			count = 0;
			for (i = 1; i < n; i++) {
				for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				}

			}
			System.out.println(count);
		} flag {
			n = stdIn.nextInt();
			x = stdIn.nextInt();

			if (n == 0 && x == 0) {
				flag = false;
				break;
			}

			count = 0;
			for (i = 1; i < n; i++) {
				for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				}

			}
			System.out.println(count);
		} n = stdIn.nextInt() n stdIn.nextInt() stdIn.nextInt stdIn x = stdIn.nextInt() x stdIn.nextInt() stdIn.nextInt stdIn if (n == 0 && x == 0) {
				flag = false;
				break;
			} n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
				flag = false;
				break;
			} flag = false flag false break; count = 0 count 0 for (i = 1; i < n; i++) {
				for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				}

			} i = 1; i = 1 i 1 i < n i n i++ i++ i {
				for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				}

			} {
				for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				}

			} for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				} j = i + 1; j = i + 1 j i + 1 i 1 j < n j n j++ j++ j {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				} {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				} for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					} k = x - i - j; k = x - i - j k x - i - j x - i - j x i j k > j k j k-- k-- k {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					} {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					} if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						} x == i + j + k && k <= n x == i + j + k x i + j + k i + j + k i j k k <= n k n {
							
							count++;
						} count++ count {
							
						} System.out.println(count) System.out.println System.out System System.out count stdIn.close() stdIn.close stdIn String[] args args
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int n, x;
		int i = 0, j = 0, k = 0;
		int count = 0;
		Scanner stdIn = new Scanner(System.in);

		boolean flag = true;
		while (flag) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();

			if (n == 0 && x == 0) {
				flag = false;
				break;
			}

			count = 0;
			for (i = 1; i < n; i++) {
				for (j = i + 1; j < n; j++) {
					for (k = x - i - j; k > j; k--) {
						
						if (x == i + j + k && k <= n) {
							
							count++;
						} else {
							
						}
					}
				}

			}
			System.out.println(count);
		}
		stdIn.close();
	}
}