import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n, x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0) break;
            System.out.println(calcCombi(n, x));
        }
    }
    public static int calcCombi(int n, int x){
        if(x < 6) return 0;
        int i, j, k;
        int count = 0;
        for(i = 1; i <= n; i++){
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            }
        }
        return count;
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n, x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0) break;
            System.out.println(calcCombi(n, x));
        }
    }
    public static int calcCombi(int n, int x){
        if(x < 6) return 0;
        int i, j, k;
        int count = 0;
        for(i = 1; i <= n; i++){
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            }
        }
        return count;
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n, x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0) break;
            System.out.println(calcCombi(n, x));
        }
    } main {
        Scanner scan = new Scanner(System.in);
        int n, x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0) break;
            System.out.println(calcCombi(n, x));
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n n x; x while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0) break;
            System.out.println(calcCombi(n, x));
        } true {
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0) break;
            System.out.println(calcCombi(n, x));
        } n = scan.nextInt() n scan.nextInt() scan.nextInt scan x = scan.nextInt() x scan.nextInt() scan.nextInt scan if(n == 0 && x == 0) break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; System.out.println(calcCombi(n, x)) System.out.println System.out System System.out calcCombi(n, x) calcCombi n x String[] args args public static int calcCombi(int n, int x){
        if(x < 6) return 0;
        int i, j, k;
        int count = 0;
        for(i = 1; i <= n; i++){
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            }
        }
        return count;
    } calcCombi {
        if(x < 6) return 0;
        int i, j, k;
        int count = 0;
        for(i = 1; i <= n; i++){
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            }
        }
        return count;
    } if(x < 6) return 0; x < 6 x 6 return 0; 0 int i i j j k; k int count = 0; count 0 for(i = 1; i <= n; i++){
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            }
        } i = 1; i = 1 i 1 i <= n i n i++ i++ i {
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            }
        } {
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            }
        } for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            } j = i + 1; j = i + 1 j i + 1 i 1 j <= n j n j++ j++ j {
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            } {
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                }
            } for(k = j + 1; k <= n; k++){
                    if(i + j + k == x) count++;
                } k = j + 1; k = j + 1 k j + 1 j 1 k <= n k n k++ k++ k {
                    if(i + j + k == x) count++;
                } {
                    if(i + j + k == x) count++;
                } if(i + j + k == x) count++; i + j + k == x i + j + k i + j + k i j k x count++ count return count; count int n n int x x
import java.util.Scanner;

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