import java.util.Scanner;

class NumClass{
	public int max;
	public int sum;
}
	

class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int i,j,k;
	  	int count;
	  	
	  	NumClass num = new NumClass();
	  	
	  	while(true){
	  		count = 0;
	  		num.max = scanner.nextInt();
	  		num.sum = scanner.nextInt();
		  	
		  	if(num.max == 0 && num.sum == 0)
		  		break;
		  	
		  	for(i = 1; i <= num.max - 2 ; i ++){
		  		for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		}
		  	}

			System.out.println(count);
	  		
	  	}
        scanner.close();
  }
} import java.util.Scanner; Scanner java.util class NumClass{
	public int max;
	public int sum;
} NumClass public int max; max public int sum; sum class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int i,j,k;
	  	int count;
	  	
	  	NumClass num = new NumClass();
	  	
	  	while(true){
	  		count = 0;
	  		num.max = scanner.nextInt();
	  		num.sum = scanner.nextInt();
		  	
		  	if(num.max == 0 && num.sum == 0)
		  		break;
		  	
		  	for(i = 1; i <= num.max - 2 ; i ++){
		  		for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		}
		  	}

			System.out.println(count);
	  		
	  	}
        scanner.close();
  }
} Main public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int i,j,k;
	  	int count;
	  	
	  	NumClass num = new NumClass();
	  	
	  	while(true){
	  		count = 0;
	  		num.max = scanner.nextInt();
	  		num.sum = scanner.nextInt();
		  	
		  	if(num.max == 0 && num.sum == 0)
		  		break;
		  	
		  	for(i = 1; i <= num.max - 2 ; i ++){
		  		for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		}
		  	}

			System.out.println(count);
	  		
	  	}
        scanner.close();
  } main {
	  	Scanner scanner = new Scanner(System.in);
	  	int i,j,k;
	  	int count;
	  	
	  	NumClass num = new NumClass();
	  	
	  	while(true){
	  		count = 0;
	  		num.max = scanner.nextInt();
	  		num.sum = scanner.nextInt();
		  	
		  	if(num.max == 0 && num.sum == 0)
		  		break;
		  	
		  	for(i = 1; i <= num.max - 2 ; i ++){
		  		for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		}
		  	}

			System.out.println(count);
	  		
	  	}
        scanner.close();
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int i i j j k; k int count; count NumClass num = new NumClass(); num new NumClass() while(true){
	  		count = 0;
	  		num.max = scanner.nextInt();
	  		num.sum = scanner.nextInt();
		  	
		  	if(num.max == 0 && num.sum == 0)
		  		break;
		  	
		  	for(i = 1; i <= num.max - 2 ; i ++){
		  		for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		}
		  	}

			System.out.println(count);
	  		
	  	} true {
	  		count = 0;
	  		num.max = scanner.nextInt();
	  		num.sum = scanner.nextInt();
		  	
		  	if(num.max == 0 && num.sum == 0)
		  		break;
		  	
		  	for(i = 1; i <= num.max - 2 ; i ++){
		  		for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		}
		  	}

			System.out.println(count);
	  		
	  	} count = 0 count 0 num.max = scanner.nextInt() num.max num num.max scanner.nextInt() scanner.nextInt scanner num.sum = scanner.nextInt() num.sum num num.sum scanner.nextInt() scanner.nextInt scanner if(num.max == 0 && num.sum == 0)
		  		break; num.max == 0 && num.sum == 0 num.max == 0 num.max num num.max 0 num.sum == 0 num.sum num num.sum 0 break; for(i = 1; i <= num.max - 2 ; i ++){
		  		for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		}
		  	} i = 1; i = 1 i 1 i <= num.max - 2 i num.max - 2 num.max num num.max 2 i ++ i ++ i {
		  		for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		}
		  	} {
		  		for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		}
		  	} for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		} j = i + 1; j = i + 1 j i + 1 i 1 j <= num.max - 1 j num.max - 1 num.max num num.max 1 j ++ j ++ j {
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		} {
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		} for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			} k = j + 1; k = j + 1 k j + 1 j 1 k <= num.max k num.max num num.max k ++ k ++ k {
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			} {
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			} if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				} i + j + k == num.sum i + j + k i + j + k i j k num.sum num num.sum {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				} count ++ count if(i == k || j == k || i == j)
		  						count --; i == k || j == k || i == j i == k || j == k || i == j i == k i k j == k j k i == j i j count -- count System.out.println(count) System.out.println System.out System System.out count scanner.close() scanner.close scanner String args[] args
import java.util.Scanner;

class NumClass{
	public int max;
	public int sum;
}
	

class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int i,j,k;
	  	int count;
	  	
	  	NumClass num = new NumClass();
	  	
	  	while(true){
	  		count = 0;
	  		num.max = scanner.nextInt();
	  		num.sum = scanner.nextInt();
		  	
		  	if(num.max == 0 && num.sum == 0)
		  		break;
		  	
		  	for(i = 1; i <= num.max - 2 ; i ++){
		  		for( j = i + 1; j <= num.max - 1; j ++ ){
		  			for(k = j + 1; k <= num.max ; k ++){
		  				if(i + j + k == num.sum) {
		  					count ++;
		  					if(i == k || j == k || i == j)
		  						count --;
		  				}
		  			}
		  		}
		  	}

			System.out.println(count);
	  		
	  	}
        scanner.close();
  }
}
