import java.util.Scanner;

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

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

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


