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 a=1; a<=n; a++){
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == 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 a=1; a<=n; a++){
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == 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 a=1; a<=n; a++){
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == 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 a=1; a<=n; a++){
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == 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 a=1; a<=n; a++){
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == 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 a=1; a<=n; a++){
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == 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; int count = 0; count 0 for(int a=1; a<=n; a++){
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == x) {
							count++;
						}
					}
				}
			} int a=1; int a=1; a 1 a<=n a n a++ a++ a {
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == x) {
							count++;
						}
					}
				}
			} {
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == x) {
							count++;
						}
					}
				}
			} for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == x) {
							count++;
						}
					}
				} int b=a+1; int b=a+1; b a+1 a 1 b<=n b n b++ b++ b {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == x) {
							count++;
						}
					}
				} {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == x) {
							count++;
						}
					}
				} for (int c=b+1; c<=n; c++) {
						if (a+b+c == x) {
							count++;
						}
					} int c=b+1; int c=b+1; c b+1 b 1 c<=n c n c++ c++ c {
						if (a+b+c == x) {
							count++;
						}
					} {
						if (a+b+c == x) {
							count++;
						}
					} if (a+b+c == x) {
							count++;
						} a+b+c == x a+b+c a+b+c a b c 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 a=1; a<=n; a++){
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == 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 a=1; a<=n; a++){
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == 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 a=1; a<=n; a++){
				for (int b=a+1; b<=n; b++) {
					for (int c=b+1; c<=n; c++) {
						if (a+b+c == x) {
							count++;
						}
					}
				}
			}
			
			
			
			System.out.println(count); 
		} 
	} 
}
