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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true) {
			int cnt = 0;
			String[] line = br.readLine().split(" ");

			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
			int[] set = new int[n];

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

			for(int i = 0; i < n; i++) {
				set[i] = i + 1;
			}

			for(int j = 0; j < n; j++) {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt + "\n");
		}
		System.out.print(sb);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true) {
			int cnt = 0;
			String[] line = br.readLine().split(" ");

			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
			int[] set = new int[n];

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

			for(int i = 0; i < n; i++) {
				set[i] = i + 1;
			}

			for(int j = 0; j < n; j++) {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt + "\n");
		}
		System.out.print(sb);
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true) {
			int cnt = 0;
			String[] line = br.readLine().split(" ");

			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
			int[] set = new int[n];

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

			for(int i = 0; i < n; i++) {
				set[i] = i + 1;
			}

			for(int j = 0; j < n; j++) {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt + "\n");
		}
		System.out.print(sb);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true) {
			int cnt = 0;
			String[] line = br.readLine().split(" ");

			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
			int[] set = new int[n];

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

			for(int i = 0; i < n; i++) {
				set[i] = i + 1;
			}

			for(int j = 0; j < n; j++) {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt + "\n");
		}
		System.out.print(sb);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() while(true) {
			int cnt = 0;
			String[] line = br.readLine().split(" ");

			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
			int[] set = new int[n];

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

			for(int i = 0; i < n; i++) {
				set[i] = i + 1;
			}

			for(int j = 0; j < n; j++) {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt + "\n");
		} true {
			int cnt = 0;
			String[] line = br.readLine().split(" ");

			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
			int[] set = new int[n];

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

			for(int i = 0; i < n; i++) {
				set[i] = i + 1;
			}

			for(int j = 0; j < n; j++) {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt + "\n");
		} int cnt = 0; cnt 0 String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(line[0]); n Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int x = Integer.parseInt(line[1]); x Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 int[] set = new int[n]; set new int[n] n if (n == 0 && x == 0) {
				break;
			} n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
				break;
			} break; for(int i = 0; i < n; i++) {
				set[i] = i + 1;
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				set[i] = i + 1;
			} {
				set[i] = i + 1;
			} set[i] = i + 1 set[i] set i i + 1 i 1 for(int j = 0; j < n; j++) {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			} int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			} {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			} for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				} int k = j + 1; int k = j + 1; k j + 1 j 1 k < n k n k++ k++ k {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				} {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				} for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					} int l = k + 1; int l = k + 1; l k + 1 k 1 l < n l n l++ l++ l {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					} {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					} if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						} x == (set[j] + set[k] + set[l]) x (set[j] + set[k] + set[l]) set[j] + set[k] + set[l] set[j] set j set[k] set k set[l] set l {
							cnt++;
						} cnt++ cnt sb.append(cnt + "\n") sb.append sb cnt + "\n" cnt "\n" System.out.print(sb) System.out.print System.out System System.out sb String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true) {
			int cnt = 0;
			String[] line = br.readLine().split(" ");

			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
			int[] set = new int[n];

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

			for(int i = 0; i < n; i++) {
				set[i] = i + 1;
			}

			for(int j = 0; j < n; j++) {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt + "\n");
		}
		System.out.print(sb);
	}
} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true) {
			int cnt = 0;
			String[] line = br.readLine().split(" ");

			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
			int[] set = new int[n];

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

			for(int i = 0; i < n; i++) {
				set[i] = i + 1;
			}

			for(int j = 0; j < n; j++) {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt + "\n");
		}
		System.out.print(sb);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true) {
			int cnt = 0;
			String[] line = br.readLine().split(" ");

			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
			int[] set = new int[n];

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

			for(int i = 0; i < n; i++) {
				set[i] = i + 1;
			}

			for(int j = 0; j < n; j++) {
				for(int k = j + 1; k < n; k++) {
					for (int l = k + 1; l < n; l++) {
						if(x == (set[j] + set[k] + set[l])) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt + "\n");
		}
		System.out.print(sb);
	}
}