import java.util.*;

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

        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            int a = 0;

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

        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            int a = 0;

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

        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            int a = 0;

            if(n == 0 && x == 0){
                break;
            }else{
                for(int i=1;i<n-1;i++){
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                }
                System.out.println(a);
            }
        }
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            int a = 0;

            if(n == 0 && x == 0){
                break;
            }else{
                for(int i=1;i<n-1;i++){
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                }
                System.out.println(a);
            }
        }
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            int a = 0;

            if(n == 0 && x == 0){
                break;
            }else{
                for(int i=1;i<n-1;i++){
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                }
                System.out.println(a);
            }
        } true {
            int n = sc.nextInt();
            int x = sc.nextInt();
            int a = 0;

            if(n == 0 && x == 0){
                break;
            }else{
                for(int i=1;i<n-1;i++){
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                }
                System.out.println(a);
            }
        } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int a = 0; a 0 if(n == 0 && x == 0){
                break;
            }else{
                for(int i=1;i<n-1;i++){
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                }
                System.out.println(a);
            } n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
                break;
            } break; {
                for(int i=1;i<n-1;i++){
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                }
                System.out.println(a);
            } for(int i=1;i<n-1;i++){
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                } int i=1; int i=1; i 1 i<n-1 i n-1 n 1 i++ i++ i {
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                } {
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                } for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    } 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+1;k++){
                            if(i+j+k == x) a++;
                        }
                    } {
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    } for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        } int k=j+1; int k=j+1; k j+1 j 1 k<n+1 k n+1 n 1 k++ k++ k {
                            if(i+j+k == x) a++;
                        } {
                            if(i+j+k == x) a++;
                        } if(i+j+k == x) a++; i+j+k == x i+j+k i+j+k i j k x a++ a System.out.println(a) System.out.println System.out System System.out a sc.close() sc.close sc String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            int a = 0;

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

        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            int a = 0;

            if(n == 0 && x == 0){
                break;
            }else{
                for(int i=1;i<n-1;i++){
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                }
                System.out.println(a);
            }
        }
        sc.close();
    }
} Main
import java.util.*;

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

        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            int a = 0;

            if(n == 0 && x == 0){
                break;
            }else{
                for(int i=1;i<n-1;i++){
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n+1;k++){
                            if(i+j+k == x) a++;
                        }
                    }
                }
                System.out.println(a);
            }
        }
        sc.close();
    }
}
