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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);
			if (n == 0 && x == 0)
				break;

			int cnt = 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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);
			if (n == 0 && x == 0)
				break;

			int cnt = 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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);
			if (n == 0 && x == 0)
				break;

			int cnt = 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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);
			if (n == 0 && x == 0)
				break;

			int cnt = 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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line; line while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);
			if (n == 0 && x == 0)
				break;

			int cnt = 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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);
		} (line = br.readLine()) != null (line = br.readLine()) line br.readLine() br.readLine br null {
			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);
			if (n == 0 && x == 0)
				break;

			int cnt = 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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);
		} String[] arr = line.split(" "); arr line.split(" ") line.split line " " int n = Integer.parseInt(arr[0]); n Integer.parseInt(arr[0]) Integer.parseInt Integer arr[0] arr 0 int x = Integer.parseInt(arr[1]); x Integer.parseInt(arr[1]) Integer.parseInt Integer arr[1] arr 1 if (n == 0 && x == 0)
				break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; int cnt = 0; cnt 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)
							cnt++;
					}
				}
			} 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)
							cnt++;
					}
				}
			} {
				for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							cnt++;
					}
				}
			} for (int j = i + 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							cnt++;
					}
				} 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)
							cnt++;
					}
				} {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							cnt++;
					}
				} for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x)
							cnt++;
					} 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)
							cnt++;
					} {
						if (i + j + k == x)
							cnt++;
					} if (i + j + k == x)
							cnt++; i + j + k == x i + j + k i + j + k i j k x cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);
			if (n == 0 && x == 0)
				break;

			int cnt = 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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);
			if (n == 0 && x == 0)
				break;

			int cnt = 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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);
			if (n == 0 && x == 0)
				break;

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