import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        int x;
        int sum=0;
        while (true) {
            n = sc.nextInt();
            x = sc.nextInt();
            if(n==0 && x==0){
                break;
            }
            int[] num;
            num = new int[n];
            int count;
            for(count=0;count<n;count++){
                num[count] = count + 1;
            }
            int i,j,k;
            for(i=0;i<n-2;i++){
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            }
        System.out.println(sum);
        sum = 0; 
        }
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        int x;
        int sum=0;
        while (true) {
            n = sc.nextInt();
            x = sc.nextInt();
            if(n==0 && x==0){
                break;
            }
            int[] num;
            num = new int[n];
            int count;
            for(count=0;count<n;count++){
                num[count] = count + 1;
            }
            int i,j,k;
            for(i=0;i<n-2;i++){
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            }
        System.out.println(sum);
        sum = 0; 
        }
        sc.close();
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        int x;
        int sum=0;
        while (true) {
            n = sc.nextInt();
            x = sc.nextInt();
            if(n==0 && x==0){
                break;
            }
            int[] num;
            num = new int[n];
            int count;
            for(count=0;count<n;count++){
                num[count] = count + 1;
            }
            int i,j,k;
            for(i=0;i<n-2;i++){
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            }
        System.out.println(sum);
        sum = 0; 
        }
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n;
        int x;
        int sum=0;
        while (true) {
            n = sc.nextInt();
            x = sc.nextInt();
            if(n==0 && x==0){
                break;
            }
            int[] num;
            num = new int[n];
            int count;
            for(count=0;count<n;count++){
                num[count] = count + 1;
            }
            int i,j,k;
            for(i=0;i<n-2;i++){
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            }
        System.out.println(sum);
        sum = 0; 
        }
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n; n int x; x int sum=0; sum 0 while (true) {
            n = sc.nextInt();
            x = sc.nextInt();
            if(n==0 && x==0){
                break;
            }
            int[] num;
            num = new int[n];
            int count;
            for(count=0;count<n;count++){
                num[count] = count + 1;
            }
            int i,j,k;
            for(i=0;i<n-2;i++){
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            }
        System.out.println(sum);
        sum = 0; 
        } true {
            n = sc.nextInt();
            x = sc.nextInt();
            if(n==0 && x==0){
                break;
            }
            int[] num;
            num = new int[n];
            int count;
            for(count=0;count<n;count++){
                num[count] = count + 1;
            }
            int i,j,k;
            for(i=0;i<n-2;i++){
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            }
        System.out.println(sum);
        sum = 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;
            } n==0 && x==0 n==0 n 0 x==0 x 0 {
                break;
            } break; int[] num; num num = new int[n] num new int[n] n int count; count for(count=0;count<n;count++){
                num[count] = count + 1;
            } count=0; count=0 count 0 count<n count n count++ count++ count {
                num[count] = count + 1;
            } {
                num[count] = count + 1;
            } num[count] = count + 1 num[count] num count count + 1 count 1 int i i j j k; k for(i=0;i<n-2;i++){
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            } i=0; i=0 i 0 i<n-2 i n-2 n 2 i++ i++ i {
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            } {
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            } for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                } j=i+1; j=i+1 j i+1 i 1 j<n-1 j n-1 n 1 j++ j++ j {
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                } {
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                } for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    } k=j+1; k=j+1 k j+1 j 1 k<n k n k++ k++ k {
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    } {
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    } if(num[i]+num[j]+num[k] == x){
                            sum++;
                        } num[i]+num[j]+num[k] == x num[i]+num[j]+num[k] num[i]+num[j]+num[k] num[i] num i num[j] num j num[k] num k x {
                            sum++;
                        } sum++ sum System.out.println(sum) System.out.println System.out System System.out sum sum = 0 sum 0 sc.close() sc.close sc String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        int x;
        int sum=0;
        while (true) {
            n = sc.nextInt();
            x = sc.nextInt();
            if(n==0 && x==0){
                break;
            }
            int[] num;
            num = new int[n];
            int count;
            for(count=0;count<n;count++){
                num[count] = count + 1;
            }
            int i,j,k;
            for(i=0;i<n-2;i++){
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            }
        System.out.println(sum);
        sum = 0; 
        }
        sc.close();
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        int x;
        int sum=0;
        while (true) {
            n = sc.nextInt();
            x = sc.nextInt();
            if(n==0 && x==0){
                break;
            }
            int[] num;
            num = new int[n];
            int count;
            for(count=0;count<n;count++){
                num[count] = count + 1;
            }
            int i,j,k;
            for(i=0;i<n-2;i++){
                for(j=i+1;j<n-1;j++){
                    for(k=j+1;k<n;k++){
                        if(num[i]+num[j]+num[k] == x){
                            sum++;
                        }
                    }
                }
            }
        System.out.println(sum);
        sum = 0; 
        }
        sc.close();
    }
} Main
import java.util.Scanner;

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