import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String[] strAry = br.readLine().split(" ");
			int n = Integer.parseInt(strAry[0]);
			int x = Integer.parseInt(strAry[1]);
			if (n == 0 && x == 0) break;
			int count = 0;
				for (int i = 1; i <= n; i ++) {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				}
				System.out.println(count);
		}
	}
} import java.io.InputStreamReader; InputStreamReader java.io import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String[] strAry = br.readLine().split(" ");
			int n = Integer.parseInt(strAry[0]);
			int x = Integer.parseInt(strAry[1]);
			if (n == 0 && x == 0) break;
			int count = 0;
				for (int i = 1; i <= n; i ++) {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				}
				System.out.println(count);
		}
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String[] strAry = br.readLine().split(" ");
			int n = Integer.parseInt(strAry[0]);
			int x = Integer.parseInt(strAry[1]);
			if (n == 0 && x == 0) break;
			int count = 0;
				for (int i = 1; i <= n; i ++) {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				}
				System.out.println(count);
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String[] strAry = br.readLine().split(" ");
			int n = Integer.parseInt(strAry[0]);
			int x = Integer.parseInt(strAry[1]);
			if (n == 0 && x == 0) break;
			int count = 0;
				for (int i = 1; i <= n; i ++) {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				}
				System.out.println(count);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) while (true) {
			String[] strAry = br.readLine().split(" ");
			int n = Integer.parseInt(strAry[0]);
			int x = Integer.parseInt(strAry[1]);
			if (n == 0 && x == 0) break;
			int count = 0;
				for (int i = 1; i <= n; i ++) {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				}
				System.out.println(count);
		} true {
			String[] strAry = br.readLine().split(" ");
			int n = Integer.parseInt(strAry[0]);
			int x = Integer.parseInt(strAry[1]);
			if (n == 0 && x == 0) break;
			int count = 0;
				for (int i = 1; i <= n; i ++) {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				}
				System.out.println(count);
		} String[] strAry = br.readLine().split(" "); strAry br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(strAry[0]); n Integer.parseInt(strAry[0]) Integer.parseInt Integer strAry[0] strAry 0 int x = Integer.parseInt(strAry[1]); x Integer.parseInt(strAry[1]) Integer.parseInt Integer strAry[1] strAry 1 if (n == 0 && x == 0) break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; int count = 0; count 0 for (int i = 1; i <= n; i ++) {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				} int i = 1; int i = 1; i 1 i <= n i n i ++ i ++ i {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				} {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				} for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					} int j = 1; int j = 1; j 1 j <= n j n j++ j++ j {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					} {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					} if (j < i) continue; j < i j i continue; for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							} int k = 1; int k = 1; k 1 k <= n k n k++ k++ k {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							} {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							} if (k < i || k < j) continue; k < i || k < j k < i k i k < j k j continue; if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								} (i + j + k) == x && i != j && j != k && k != i j != k (i + j + k) == x && i != j && j != k && k != i (i + j + k) == x (i + j + k) i + j + k i j k x i != j i j j != k j k k != i k i {
									count++;
								} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String[] strAry = br.readLine().split(" ");
			int n = Integer.parseInt(strAry[0]);
			int x = Integer.parseInt(strAry[1]);
			if (n == 0 && x == 0) break;
			int count = 0;
				for (int i = 1; i <= n; i ++) {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				}
				System.out.println(count);
		}
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String[] strAry = br.readLine().split(" ");
			int n = Integer.parseInt(strAry[0]);
			int x = Integer.parseInt(strAry[1]);
			if (n == 0 && x == 0) break;
			int count = 0;
				for (int i = 1; i <= n; i ++) {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				}
				System.out.println(count);
		}
	}
} Main
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			String[] strAry = br.readLine().split(" ");
			int n = Integer.parseInt(strAry[0]);
			int x = Integer.parseInt(strAry[1]);
			if (n == 0 && x == 0) break;
			int count = 0;
				for (int i = 1; i <= n; i ++) {
					for (int j = 1; j <= n; j++) {
						if (j < i) continue;
							for (int k = 1; k <= n; k++) {
								if (k < i || k < j) continue;
								if ((i + j + k) == x && i != j && j != k && k != i) {
									count++;
								}
							}
					}
				}
				System.out.println(count);
		}
	}
}