import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int n = Integer.parseInt(array[0]);
			int x = Integer.parseInt(array[1]);
			int count = 0;
			if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			}
			System.out.println(count);
		}

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int n = Integer.parseInt(array[0]);
			int x = Integer.parseInt(array[1]);
			int count = 0;
			if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			}
			System.out.println(count);
		}

	}

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

		while (true) {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int n = Integer.parseInt(array[0]);
			int x = Integer.parseInt(array[1]);
			int count = 0;
			if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			}
			System.out.println(count);
		}

	} main {
		Scanner sc = new Scanner(System.in);

		while (true) {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int n = Integer.parseInt(array[0]);
			int x = Integer.parseInt(array[1]);
			int count = 0;
			if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			}
			System.out.println(count);
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while (true) {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int n = Integer.parseInt(array[0]);
			int x = Integer.parseInt(array[1]);
			int count = 0;
			if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			}
			System.out.println(count);
		} true {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int n = Integer.parseInt(array[0]);
			int x = Integer.parseInt(array[1]);
			int count = 0;
			if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			}
			System.out.println(count);
		} String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String[] array = line.split(" "); array line.split(" ") line.split line " " int n = Integer.parseInt(array[0]); n Integer.parseInt(array[0]) Integer.parseInt Integer array[0] array 0 int x = Integer.parseInt(array[1]); x Integer.parseInt(array[1]) Integer.parseInt Integer array[1] array 1 int count = 0; count 0 if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			} n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
				break;
			} break; {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			} for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				} int j = 1; int j = 1; j 1 j <= n j n j++ j++ j {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				} {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				} for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					} int k = j + 1; int k = j + 1; k j + 1 j 1 k <= n k n k++ k++ k {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					} {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					} for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						} int p = k + 1; int p = k + 1; p k + 1 k 1 p <= n p n p++ p++ p {
							if (j + k + p == x)
								count++;
						} {
							if (j + k + p == x)
								count++;
						} if (j + k + p == x)
								count++; j + k + p == x j + k + p j + k + p j k p x 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) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int n = Integer.parseInt(array[0]);
			int x = Integer.parseInt(array[1]);
			int count = 0;
			if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			}
			System.out.println(count);
		}

	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int n = Integer.parseInt(array[0]);
			int x = Integer.parseInt(array[1]);
			int count = 0;
			if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			}
			System.out.println(count);
		}

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while (true) {
			String line = sc.nextLine();
			String[] array = line.split(" ");
			int n = Integer.parseInt(array[0]);
			int x = Integer.parseInt(array[1]);
			int count = 0;
			if (n == 0 && x == 0) {
				break;
			} else {
				for (int j = 1; j <= n; j++) {
					for (int k = j + 1; k <= n; k++) {
						for (int p = k + 1; p <= n; p++) {
							if (j + k + p == x)
								count++;
						}
					}
				}

			}
			System.out.println(count);
		}

	}

}