import java.util.Scanner;

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

    while(true){ 
    	
    	int n = scan.nextInt();
        int x = scan.nextInt();
    	if(n==0 && x==0){
	 		break;
	 	}
    	else{
        int first;
        int second;
        int third;
        int count = 0;

        for(first = 1; first <= (n-2); first++){
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        }
        System.out.println(count);
    	}
    }
 	}
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

    while(true){ 
    	
    	int n = scan.nextInt();
        int x = scan.nextInt();
    	if(n==0 && x==0){
	 		break;
	 	}
    	else{
        int first;
        int second;
        int third;
        int count = 0;

        for(first = 1; first <= (n-2); first++){
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        }
        System.out.println(count);
    	}
    }
 	}
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

    while(true){ 
    	
    	int n = scan.nextInt();
        int x = scan.nextInt();
    	if(n==0 && x==0){
	 		break;
	 	}
    	else{
        int first;
        int second;
        int third;
        int count = 0;

        for(first = 1; first <= (n-2); first++){
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        }
        System.out.println(count);
    	}
    }
 	} main {
        Scanner scan = new Scanner(System.in);

    while(true){ 
    	
    	int n = scan.nextInt();
        int x = scan.nextInt();
    	if(n==0 && x==0){
	 		break;
	 	}
    	else{
        int first;
        int second;
        int third;
        int count = 0;

        for(first = 1; first <= (n-2); first++){
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        }
        System.out.println(count);
    	}
    }
 	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) while(true){ 
    	
    	int n = scan.nextInt();
        int x = scan.nextInt();
    	if(n==0 && x==0){
	 		break;
	 	}
    	else{
        int first;
        int second;
        int third;
        int count = 0;

        for(first = 1; first <= (n-2); first++){
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        }
        System.out.println(count);
    	}
    } true { 
    	
    	int n = scan.nextInt();
        int x = scan.nextInt();
    	if(n==0 && x==0){
	 		break;
	 	}
    	else{
        int first;
        int second;
        int third;
        int count = 0;

        for(first = 1; first <= (n-2); first++){
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        }
        System.out.println(count);
    	}
    } int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan if(n==0 && x==0){
	 		break;
	 	}
    	else{
        int first;
        int second;
        int third;
        int count = 0;

        for(first = 1; first <= (n-2); first++){
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        }
        System.out.println(count);
    	} n==0 && x==0 n==0 n 0 x==0 x 0 {
	 		break;
	 	} break; {
        int first;
        int second;
        int third;
        int count = 0;

        for(first = 1; first <= (n-2); first++){
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        }
        System.out.println(count);
    	} int first; first int second; second int third; third int count = 0; count 0 for(first = 1; first <= (n-2); first++){
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        } first = 1; first = 1 first 1 first <= (n-2) first (n-2) n 2 first++ first++ first {
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        } {
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        } for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	} second = (first+1); second = (first+1) second (first+1) first 1 second <= (n-1) second (n-1) n 1 second++ second++ second {
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	} {
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	} for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		} third = (second+1); third = (second+1) third (second+1) second 1 third <= n third n third++ third++ third {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		} {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		} if(n==0 && x==0){
        	 		break;
        	 	} n==0 && x==0 n==0 n 0 x==0 x 0 {
        	 		break;
        	 	} break; if((first + second + third) == x){
        			count++;
        		} (first + second + third) == x (first + second + third) first + second + third first second third x {
        			count++;
        		} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.Scanner;

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

    while(true){ 
    	
    	int n = scan.nextInt();
        int x = scan.nextInt();
    	if(n==0 && x==0){
	 		break;
	 	}
    	else{
        int first;
        int second;
        int third;
        int count = 0;

        for(first = 1; first <= (n-2); first++){
        	 for(second = (first+1); second <= (n-1); second++){
        	 	for(third = (second+1); third <= n; third++) {
      
        	 	if(n==0 && x==0){
        	 		break;
        	 	}
        		if((first + second + third) == x){
        			count++;
        		}
        		}
        	}
        }
        System.out.println(count);
    	}
    }
 	}
}