import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int i,j,k,l,n,x,count=0;
        for(i=0;;i++){
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        }
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int i,j,k,l,n,x,count=0;
        for(i=0;;i++){
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        }
    }
} Main public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int i,j,k,l,n,x,count=0;
        for(i=0;;i++){
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        }
    } main {
        Scanner sc=new Scanner(System.in);
        int i,j,k,l,n,x,count=0;
        for(i=0;;i++){
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        }
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int i i j j k k l l n n x x count=0; count 0 for(i=0;;i++){
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        } i=0; i=0 i 0 i++ i++ i {
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        } {
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        } n=sc.nextInt() n sc.nextInt() sc.nextInt sc x=sc.nextInt() x sc.nextInt() sc.nextInt sc if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } (n==0)&&(x==0) (n==0) n 0 (x==0) x 0 {
                break;
            } break; {
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                } j=1; j=1 j 1 j<=n-2 j n-2 n 2 j++ j++ j {
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                } {
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                } for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    } k=j+1; k=j+1 k j+1 j 1 k<=n-1 k n-1 n 1 k++ k++ k {
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    } {
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    } for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        } l=k+1; l=k+1 l k+1 k 1 l<=n l n l++ l++ l {
                            if(j+k+l==x){
                                count += 1;
                            }
                        } {
                            if(j+k+l==x){
                                count += 1;
                            }
                        } if(j+k+l==x){
                                count += 1;
                            } j+k+l==x j+k+l j+k+l j k l x {
                                count += 1;
                            } count += 1 count 1 System.out.println(count) System.out.println System.out System System.out count count=0 count 0 String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int i,j,k,l,n,x,count=0;
        for(i=0;;i++){
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        }
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int i,j,k,l,n,x,count=0;
        for(i=0;;i++){
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        }
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int i,j,k,l,n,x,count=0;
        for(i=0;;i++){
            n=sc.nextInt();
            x=sc.nextInt();
            if((n==0)&&(x==0)){
                break;
            }else{
                for(j=1;j<=n-2;j++){
                    for(k=j+1;k<=n-1;k++){
                        for(l=k+1;l<=n;l++){
                            if(j+k+l==x){
                                count += 1;
                            }
                        }
                    }
                }
                System.out.println(count);
                count=0;
            } 
        }
    }
}
