import java.util.Scanner;

class Main {

	public static void main(String args[]){	
		Scanner scan = new Scanner(System.in);

		int n = 0, x = 0;

		while(true){
			int sum = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n == 0 && x == 0)break;
			
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				}
			}
			System.out.println(sum);
			
		}
		
	}
}	 import java.util.Scanner; Scanner java.util class Main {

	public static void main(String args[]){	
		Scanner scan = new Scanner(System.in);

		int n = 0, x = 0;

		while(true){
			int sum = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n == 0 && x == 0)break;
			
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				}
			}
			System.out.println(sum);
			
		}
		
	}
} Main public static void main(String args[]){	
		Scanner scan = new Scanner(System.in);

		int n = 0, x = 0;

		while(true){
			int sum = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n == 0 && x == 0)break;
			
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				}
			}
			System.out.println(sum);
			
		}
		
	} main {	
		Scanner scan = new Scanner(System.in);

		int n = 0, x = 0;

		while(true){
			int sum = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n == 0 && x == 0)break;
			
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				}
			}
			System.out.println(sum);
			
		}
		
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = 0 n 0 x = 0; x 0 while(true){
			int sum = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n == 0 && x == 0)break;
			
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				}
			}
			System.out.println(sum);
			
		} true {
			int sum = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n == 0 && x == 0)break;
			
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				}
			}
			System.out.println(sum);
			
		} int sum = 0; sum 0 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; for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				}
			} int i = 1; int i = 1; i 1 i <= n - 2 i n - 2 n 2 i++ i++ i {
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				}
			} {
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				}
			} for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				} 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; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				} {
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				} for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					} int k = j + 1; int k = j + 1; k j + 1 j 1 k <= n k n k ++ k ++ k {
						if(i + j + k == x){
							sum++;
						}
					} {
						if(i + j + k == x){
							sum++;
						}
					} if(i + j + k == x){
							sum++;
						} i + j + k == x i + j + k i + j + k i j k x {
							sum++;
						} sum++ sum System.out.println(sum) System.out.println System.out System System.out sum String args[] args
import java.util.Scanner;

class Main {

	public static void main(String args[]){	
		Scanner scan = new Scanner(System.in);

		int n = 0, x = 0;

		while(true){
			int sum = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n == 0 && x == 0)break;
			
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k ++){
						if(i + j + k == x){
							sum++;
						}
					}
				}
			}
			System.out.println(sum);
			
		}
		
	}
}	