import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean can=true;

        while(can){
            int n=sc.nextInt();
            int x=sc.nextInt();
            int num=0;
            if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean can=true;

        while(can){
            int n=sc.nextInt();
            int x=sc.nextInt();
            int num=0;
            if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        }
        }
    }
} Main public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean can=true;

        while(can){
            int n=sc.nextInt();
            int x=sc.nextInt();
            int num=0;
            if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        }
        }
    } main {
        Scanner sc=new Scanner(System.in);
        boolean can=true;

        while(can){
            int n=sc.nextInt();
            int x=sc.nextInt();
            int num=0;
            if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        }
        }
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) boolean can=true; can true while(can){
            int n=sc.nextInt();
            int x=sc.nextInt();
            int num=0;
            if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        }
        } can {
            int n=sc.nextInt();
            int x=sc.nextInt();
            int num=0;
            if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        }
        } int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int x=sc.nextInt(); x sc.nextInt() sc.nextInt sc int num=0; num 0 if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        } (n==0)&&(x==0) (n==0) n 0 (x==0) x 0 can=false can false {
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        } for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            } {
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            } for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                } int j=i+1; int j=i+1; j i+1 i 1 j<=n j n j++ j++ j {
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                } {
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                } for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    } int k=j+1; int k=j+1; k j+1 j 1 k<=n k n k++ k++ k {
                       if(x==i+j+k)num++;
                    } {
                       if(x==i+j+k)num++;
                    } if(x==i+j+k)num++; x==i+j+k x i+j+k i+j+k i j k num++ num System.out.println(num) System.out.println System.out System System.out num String[] args args public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean can=true;

        while(can){
            int n=sc.nextInt();
            int x=sc.nextInt();
            int num=0;
            if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        }
        }
    }
} public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean can=true;

        while(can){
            int n=sc.nextInt();
            int x=sc.nextInt();
            int num=0;
            if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        }
        }
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean can=true;

        while(can){
            int n=sc.nextInt();
            int x=sc.nextInt();
            int num=0;
            if((n==0)&&(x==0))can=false;
            else{
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                       if(x==i+j+k)num++;
                    }
                }
            }
            System.out.println(num);
        }
        }
    }
}
