import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n, x, i, j, k, count;
		while (true) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			count=0;
			if (n == 0 && x == 0) {
				break;
			}
			for (i = 1; i <= n; i++) {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		stdIn.close();
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n, x, i, j, k, count;
		while (true) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			count=0;
			if (n == 0 && x == 0) {
				break;
			}
			for (i = 1; i <= n; i++) {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		stdIn.close();
	}
} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n, x, i, j, k, count;
		while (true) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			count=0;
			if (n == 0 && x == 0) {
				break;
			}
			for (i = 1; i <= n; i++) {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		stdIn.close();
	} main {
		Scanner stdIn = new Scanner(System.in);
		int n, x, i, j, k, count;
		while (true) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			count=0;
			if (n == 0 && x == 0) {
				break;
			}
			for (i = 1; i <= n; i++) {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		stdIn.close();
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n n x x i i j j k k count; count while (true) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			count=0;
			if (n == 0 && x == 0) {
				break;
			}
			for (i = 1; i <= n; i++) {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		} true {
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			count=0;
			if (n == 0 && x == 0) {
				break;
			}
			for (i = 1; i <= n; i++) {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		} n = stdIn.nextInt() n stdIn.nextInt() stdIn.nextInt stdIn x = stdIn.nextInt() x stdIn.nextInt() stdIn.nextInt stdIn count=0 count 0 if (n == 0 && x == 0) {
				break;
			} n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
				break;
			} break; for (i = 1; i <= n; i++) {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			} i = 1; i = 1 i 1 i <= n i n i++ i++ i {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			} {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			} for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				} j = i+1; j = i+1 j i+1 i 1 j < n j n j++ j++ j {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				} {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				} for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					} k = j+1; k = j+1 k j+1 j 1 k <= n k n k++ k++ k {
						if (i + j + k == x) {
							count++;
						}
					} {
						if (i + j + k == x) {
							count++;
						}
					} if (i + j + k == x) {
							count++;
						} i + j + k == x i + j + k i + j + k i j k x {
							count++;
						} count++ count System.out.println(count) System.out.println System.out System System.out count stdIn.close() stdIn.close stdIn String[] args args public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n, x, i, j, k, count;
		while (true) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			count=0;
			if (n == 0 && x == 0) {
				break;
			}
			for (i = 1; i <= n; i++) {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		stdIn.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n, x, i, j, k, count;
		while (true) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			count=0;
			if (n == 0 && x == 0) {
				break;
			}
			for (i = 1; i <= n; i++) {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		stdIn.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n, x, i, j, k, count;
		while (true) {
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			count=0;
			if (n == 0 && x == 0) {
				break;
			}
			for (i = 1; i <= n; i++) {
				for (j = i+1; j < n; j++) {
					for (k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		stdIn.close();
	}
}

