import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i1 = 1; i1 <= n-2; i1++) {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == 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) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i1 = 1; i1 <= n-2; i1++) {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i1 = 1; i1 <= n-2; i1++) {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i1 = 1; i1 <= n-2; i1++) {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while(true) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i1 = 1; i1 <= n-2; i1++) {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		} true {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i1 = 1; i1 <= n-2; i1++) {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		} 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; int count = 0; count 0 for (int i1 = 1; i1 <= n-2; i1++) {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				}
			} int i1 = 1; int i1 = 1; i1 1 i1 <= n-2 i1 n-2 n 2 i1++ i1++ i1 {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				}
			} {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				}
			} for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				} int i2 = i1+1; int i2 = i1+1; i2 i1+1 i1 1 i2 <= n-1 i2 n-1 n 1 i2++ i2++ i2 {
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				} {
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				} for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					} int i3 = i2+1; int i3 = i2+1; i3 i2+1 i2 1 i3 <= n i3 n i3++ i3++ i3 {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					} {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					} if (i1 + i2 + i3 == x) {
							count++;
						} i1 + i2 + i3 == x i1 + i2 + i3 i1 + i2 + i3 i1 i2 i3 x {
							count++;
						} 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) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i1 = 1; i1 <= n-2; i1++) {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i1 = 1; i1 <= n-2; i1++) {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == 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) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int i1 = 1; i1 <= n-2; i1++) {
				for (int i2 = i1+1; i2 <= n-1; i2++){
					for (int i3 = i2+1; i3 <= n; i3++) {
						if (i1 + i2 + i3 == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}

}