import java.util.Scanner;
 
class Main{
	public static void main(String[] args){
        	Scanner sc = new Scanner(System.in);
	        int x,y,z;
        	while(true){
            		x = sc.nextInt();
            		y = sc.nextInt();
            		if( x == 0 && y == 0 ){
				 break;
			}
            		z = 0;
            		for(int i = 1; i <= x-2; i++){
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	}
          	System.out.println(z);
        	}
    	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args){
        	Scanner sc = new Scanner(System.in);
	        int x,y,z;
        	while(true){
            		x = sc.nextInt();
            		y = sc.nextInt();
            		if( x == 0 && y == 0 ){
				 break;
			}
            		z = 0;
            		for(int i = 1; i <= x-2; i++){
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	}
          	System.out.println(z);
        	}
    	}
} Main public static void main(String[] args){
        	Scanner sc = new Scanner(System.in);
	        int x,y,z;
        	while(true){
            		x = sc.nextInt();
            		y = sc.nextInt();
            		if( x == 0 && y == 0 ){
				 break;
			}
            		z = 0;
            		for(int i = 1; i <= x-2; i++){
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	}
          	System.out.println(z);
        	}
    	} main {
        	Scanner sc = new Scanner(System.in);
	        int x,y,z;
        	while(true){
            		x = sc.nextInt();
            		y = sc.nextInt();
            		if( x == 0 && y == 0 ){
				 break;
			}
            		z = 0;
            		for(int i = 1; i <= x-2; i++){
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	}
          	System.out.println(z);
        	}
    	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x x y y z; z while(true){
            		x = sc.nextInt();
            		y = sc.nextInt();
            		if( x == 0 && y == 0 ){
				 break;
			}
            		z = 0;
            		for(int i = 1; i <= x-2; i++){
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	}
          	System.out.println(z);
        	} true {
            		x = sc.nextInt();
            		y = sc.nextInt();
            		if( x == 0 && y == 0 ){
				 break;
			}
            		z = 0;
            		for(int i = 1; i <= x-2; i++){
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	}
          	System.out.println(z);
        	} x = sc.nextInt() x sc.nextInt() sc.nextInt sc y = sc.nextInt() y sc.nextInt() sc.nextInt sc if( x == 0 && y == 0 ){
				 break;
			} x == 0 && y == 0 x == 0 x 0 y == 0 y 0 {
				 break;
			} break; z = 0 z 0 for(int i = 1; i <= x-2; i++){
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	} int i = 1; int i = 1; i 1 i <= x-2 i x-2 x 2 i++ i++ i {
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	} {
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	} for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				} int j = 2; int j = 2; j 2 j <= x-1 j x-1 x 1 j++ j++ j {
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				} {
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				} for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					} int k = 3; int k = 3; k 3 k <= x k x k++ k++ k {
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					} {
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					} if(i >= j || i >= k || j >= k){
							 continue;
                        			} i >= j || i >= k || j >= k i >= j || i >= k || j >= k i >= j i j i >= k i k j >= k j k {
							 continue;
                        			} continue; if(i + j + k == y){
							 z++;
						} i + j + k == y i + j + k i + j + k i j k y {
							 z++;
						} z++ z System.out.println(z) System.out.println System.out System System.out z String[] args args
import java.util.Scanner;
 
class Main{
	public static void main(String[] args){
        	Scanner sc = new Scanner(System.in);
	        int x,y,z;
        	while(true){
            		x = sc.nextInt();
            		y = sc.nextInt();
            		if( x == 0 && y == 0 ){
				 break;
			}
            		z = 0;
            		for(int i = 1; i <= x-2; i++){
                		for(int j = 2; j <= x-1; j++){
                    			for(int k = 3; k <= x; k++){
                        			if(i >= j || i >= k || j >= k){
							 continue;
                        			}
						if(i + j + k == y){
							 z++;
						}
					}
				}
                    	}
          	System.out.println(z);
        	}
    	}
}