import java.util.Scanner;


public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			long ways = 0;
			
			
			long n = sc.nextInt();
			long x = sc.nextInt();
			
			if(n == 0 && x == 0) break;
			
			for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			}
			
			System.out.println(ways);
			
			
		}

	}
	

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			long ways = 0;
			
			
			long n = sc.nextInt();
			long x = sc.nextInt();
			
			if(n == 0 && x == 0) break;
			
			for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			}
			
			System.out.println(ways);
			
			
		}

	}
	

} Main public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			long ways = 0;
			
			
			long n = sc.nextInt();
			long x = sc.nextInt();
			
			if(n == 0 && x == 0) break;
			
			for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			}
			
			System.out.println(ways);
			
			
		}

	} main {
		
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			long ways = 0;
			
			
			long n = sc.nextInt();
			long x = sc.nextInt();
			
			if(n == 0 && x == 0) break;
			
			for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			}
			
			System.out.println(ways);
			
			
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while(true) {
			
			long ways = 0;
			
			
			long n = sc.nextInt();
			long x = sc.nextInt();
			
			if(n == 0 && x == 0) break;
			
			for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			}
			
			System.out.println(ways);
			
			
		} true {
			
			long ways = 0;
			
			
			long n = sc.nextInt();
			long x = sc.nextInt();
			
			if(n == 0 && x == 0) break;
			
			for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			}
			
			System.out.println(ways);
			
			
		} long ways = 0; ways 0 long n = sc.nextInt(); n sc.nextInt() sc.nextInt sc long 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; for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			} long i = 1; long i = 1; i 1 i <= n -2 i n -2 n 2 i++ i++ i {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			} {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			} for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				} long j = i + 1; long j = i + 1; j i + 1 i 1 j <= n - 1 j n - 1 n 1 j++ j++ j {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				} {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				} for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					} long k = j + 1; long k = j + 1; k j + 1 j 1 k <= n k n k++ k++ k {
						if(i + j + k == x)ways++;
						
					} {
						if(i + j + k == x)ways++;
						
					} if(i + j + k == x)ways++; i + j + k == x i + j + k i + j + k i j k x ways++ ways System.out.println(ways) System.out.println System.out System System.out ways String [] args args public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			long ways = 0;
			
			
			long n = sc.nextInt();
			long x = sc.nextInt();
			
			if(n == 0 && x == 0) break;
			
			for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			}
			
			System.out.println(ways);
			
			
		}

	}
	

} public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			long ways = 0;
			
			
			long n = sc.nextInt();
			long x = sc.nextInt();
			
			if(n == 0 && x == 0) break;
			
			for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			}
			
			System.out.println(ways);
			
			
		}

	}
	

} Main
import java.util.Scanner;


public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			long ways = 0;
			
			
			long n = sc.nextInt();
			long x = sc.nextInt();
			
			if(n == 0 && x == 0) break;
			
			for(long i = 1;i <= n -2;i++) {  //一個目の数（n-2通り）
				
				for(long j = i + 1;j <= n - 1;j++) {  //二個目の数（それぞれn-i-1）通り
					
					for(long k = j + 1;k <= n;k++) {
						if(i + j + k == x)ways++;
						
					}
					
				}
				
			}
			
			System.out.println(ways);
			
			
		}

	}
	

}
