import java.util.Scanner;


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

		int i;
		int j;
		int k;

		while(true) {

			int total = 0;
			int cnt = 0;

			int n = sc.nextInt();
			int x = sc.nextInt();

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

			for(i = 1; i <= n - 2; i++) {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			}
			System.out.println(cnt);

		}

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

		int i;
		int j;
		int k;

		while(true) {

			int total = 0;
			int cnt = 0;

			int n = sc.nextInt();
			int x = sc.nextInt();

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

			for(i = 1; i <= n - 2; i++) {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			}
			System.out.println(cnt);

		}

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

		int i;
		int j;
		int k;

		while(true) {

			int total = 0;
			int cnt = 0;

			int n = sc.nextInt();
			int x = sc.nextInt();

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

			for(i = 1; i <= n - 2; i++) {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			}
			System.out.println(cnt);

		}

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

		int i;
		int j;
		int k;

		while(true) {

			int total = 0;
			int cnt = 0;

			int n = sc.nextInt();
			int x = sc.nextInt();

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

			for(i = 1; i <= n - 2; i++) {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			}
			System.out.println(cnt);

		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int i; i int j; j int k; k while(true) {

			int total = 0;
			int cnt = 0;

			int n = sc.nextInt();
			int x = sc.nextInt();

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

			for(i = 1; i <= n - 2; i++) {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			}
			System.out.println(cnt);

		} true {

			int total = 0;
			int cnt = 0;

			int n = sc.nextInt();
			int x = sc.nextInt();

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

			for(i = 1; i <= n - 2; i++) {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			}
			System.out.println(cnt);

		} int total = 0; total 0 int cnt = 0; cnt 0 int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc 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 - 2; i++) {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			} i = 1; i = 1 i 1 i <= n - 2 i n - 2 n 2 i++ i++ i {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			} {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			} for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				} j = i + 1; j = i + 1 j i + 1 i 1 j <= n - 1 j n - 1 n 1 j++ j++ j {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				} {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				} for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					} k = j + 1; k = j + 1 k j + 1 j 1 k <= n k n k++ k++ k {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					} {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					} total= i + j + k total i + j + k i + j + k i j k if(total == x) {
							cnt++;
						} total == x total x {
							cnt++;
						} 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) {
		Scanner sc = new Scanner(System.in);

		int i;
		int j;
		int k;

		while(true) {

			int total = 0;
			int cnt = 0;

			int n = sc.nextInt();
			int x = sc.nextInt();

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

			for(i = 1; i <= n - 2; i++) {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			}
			System.out.println(cnt);

		}

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

		int i;
		int j;
		int k;

		while(true) {

			int total = 0;
			int cnt = 0;

			int n = sc.nextInt();
			int x = sc.nextInt();

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

			for(i = 1; i <= n - 2; i++) {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			}
			System.out.println(cnt);

		}

	}
} Main
import java.util.Scanner;


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

		int i;
		int j;
		int k;

		while(true) {

			int total = 0;
			int cnt = 0;

			int n = sc.nextInt();
			int x = sc.nextInt();

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

			for(i = 1; i <= n - 2; i++) {
				for(j = i + 1; j <= n - 1; j++) {
					for(k = j + 1; k <= n; k++) {

						total= i + j + k;

						if(total == x) {
							cnt++;
						}

					}
				}
			}
			System.out.println(cnt);

		}

	}
}