import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int n, x;
		while(true) {
			n = scan.nextInt();
			x = scan.nextInt();
			if (n == 0 && x == 0){break;}
			int i, j, k;
			int count = 0;
			for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			}
			sb.append(count + "\n");
		}
		System.out.print(sb);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int n, x;
		while(true) {
			n = scan.nextInt();
			x = scan.nextInt();
			if (n == 0 && x == 0){break;}
			int i, j, k;
			int count = 0;
			for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			}
			sb.append(count + "\n");
		}
		System.out.print(sb);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int n, x;
		while(true) {
			n = scan.nextInt();
			x = scan.nextInt();
			if (n == 0 && x == 0){break;}
			int i, j, k;
			int count = 0;
			for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			}
			sb.append(count + "\n");
		}
		System.out.print(sb);
	} main {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int n, x;
		while(true) {
			n = scan.nextInt();
			x = scan.nextInt();
			if (n == 0 && x == 0){break;}
			int i, j, k;
			int count = 0;
			for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			}
			sb.append(count + "\n");
		}
		System.out.print(sb);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() sb.append("") sb.append sb "" int n n x; x while(true) {
			n = scan.nextInt();
			x = scan.nextInt();
			if (n == 0 && x == 0){break;}
			int i, j, k;
			int count = 0;
			for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			}
			sb.append(count + "\n");
		} true {
			n = scan.nextInt();
			x = scan.nextInt();
			if (n == 0 && x == 0){break;}
			int i, j, k;
			int count = 0;
			for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			}
			sb.append(count + "\n");
		} n = scan.nextInt() n scan.nextInt() scan.nextInt scan x = scan.nextInt() x scan.nextInt() scan.nextInt scan if (n == 0 && x == 0){break;} n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {break;} break; int i i j j k; k int count = 0; count 0 for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			} 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++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			} {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			} for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				} 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++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				} {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				} for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					} k = j+1; k = j+1 k j+1 j 1 k <= n k n k++ k++ k {
						if (i + j + k == x) {
							count += 1;
						}
					} {
						if (i + j + k == x) {
							count += 1;
						}
					} if (i + j + k == x) {
							count += 1;
						} i + j + k == x i + j + k i + j + k i j k x {
							count += 1;
						} count += 1 count 1 sb.append(count + "\n") sb.append sb count + "\n" count "\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) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int n, x;
		while(true) {
			n = scan.nextInt();
			x = scan.nextInt();
			if (n == 0 && x == 0){break;}
			int i, j, k;
			int count = 0;
			for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			}
			sb.append(count + "\n");
		}
		System.out.print(sb);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int n, x;
		while(true) {
			n = scan.nextInt();
			x = scan.nextInt();
			if (n == 0 && x == 0){break;}
			int i, j, k;
			int count = 0;
			for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			}
			sb.append(count + "\n");
		}
		System.out.print(sb);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int n, x;
		while(true) {
			n = scan.nextInt();
			x = scan.nextInt();
			if (n == 0 && x == 0){break;}
			int i, j, k;
			int count = 0;
			for(i = 1; i <= n - 2; i++) {
				for(j = i+1; j <= n - 1; j++) {
					for(k = j+1; k <= n; k++) {
						if (i + j + k == x) {
							count += 1;
						}
					}
				}
			}
			sb.append(count + "\n");
		}
		System.out.print(sb);
	}
}