import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int n, x;
		while (sc.hasNext()) {
			int count = 0;
			n = Integer.parseInt(sc.next());
			x = Integer.parseInt(sc.next());
			if (n == 0 && x == 0) break;
			for (int i=1; i < n+1; i++) {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			}
			System.out.println(count);
		}
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int n, x;
		while (sc.hasNext()) {
			int count = 0;
			n = Integer.parseInt(sc.next());
			x = Integer.parseInt(sc.next());
			if (n == 0 && x == 0) break;
			for (int i=1; i < n+1; i++) {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			}
			System.out.println(count);
		}
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int n, x;
		while (sc.hasNext()) {
			int count = 0;
			n = Integer.parseInt(sc.next());
			x = Integer.parseInt(sc.next());
			if (n == 0 && x == 0) break;
			for (int i=1; i < n+1; i++) {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			}
			System.out.println(count);
		}
		sc.close();
	} main {
		Scanner sc= new Scanner(System.in);
		int n, x;
		while (sc.hasNext()) {
			int count = 0;
			n = Integer.parseInt(sc.next());
			x = Integer.parseInt(sc.next());
			if (n == 0 && x == 0) break;
			for (int i=1; i < n+1; i++) {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			}
			System.out.println(count);
		}
		sc.close();
	} Scanner sc= new Scanner(System.in); sc new Scanner(System.in) int n n x; x while (sc.hasNext()) {
			int count = 0;
			n = Integer.parseInt(sc.next());
			x = Integer.parseInt(sc.next());
			if (n == 0 && x == 0) break;
			for (int i=1; i < n+1; i++) {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			}
			System.out.println(count);
		} sc.hasNext() sc.hasNext sc {
			int count = 0;
			n = Integer.parseInt(sc.next());
			x = Integer.parseInt(sc.next());
			if (n == 0 && x == 0) break;
			for (int i=1; i < n+1; i++) {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			}
			System.out.println(count);
		} int count = 0; count 0 n = Integer.parseInt(sc.next()) n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc x = Integer.parseInt(sc.next()) x Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if (n == 0 && x == 0) break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; for (int i=1; i < n+1; i++) {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			} int i=1; int i=1; i 1 i < n+1 i n+1 n 1 i++ i++ i {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			} {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			} for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				} int j=i+1; int j=i+1; j i+1 i 1 j < n+1 j n+1 n 1 j++ j++ j {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				} {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				} for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					} int k=j+1; int k=j+1; k j+1 j 1 k < n+1 k n+1 n 1 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 System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int n, x;
		while (sc.hasNext()) {
			int count = 0;
			n = Integer.parseInt(sc.next());
			x = Integer.parseInt(sc.next());
			if (n == 0 && x == 0) break;
			for (int i=1; i < n+1; i++) {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			}
			System.out.println(count);
		}
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int n, x;
		while (sc.hasNext()) {
			int count = 0;
			n = Integer.parseInt(sc.next());
			x = Integer.parseInt(sc.next());
			if (n == 0 && x == 0) break;
			for (int i=1; i < n+1; i++) {
				for (int j=i+1; j < n+1; j++) {
					for (int k=j+1; k < n+1; k++) {
						if (i + j + k == x) count++;
					}
				}
			}
			System.out.println(count);
		}
		sc.close();
	}
} Main
import java.util.Scanner;

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