import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, s, ans = 0;
 
        for(;;){
            n = sc.nextInt();
            s = sc.nextInt();
            if(n == 0 && s == 0) break;
            for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            }
            System.out.println(ans);
            ans = 0;
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, s, ans = 0;
 
        for(;;){
            n = sc.nextInt();
            s = sc.nextInt();
            if(n == 0 && s == 0) break;
            for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            }
            System.out.println(ans);
            ans = 0;
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, s, ans = 0;
 
        for(;;){
            n = sc.nextInt();
            s = sc.nextInt();
            if(n == 0 && s == 0) break;
            for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            }
            System.out.println(ans);
            ans = 0;
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n, s, ans = 0;
 
        for(;;){
            n = sc.nextInt();
            s = sc.nextInt();
            if(n == 0 && s == 0) break;
            for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            }
            System.out.println(ans);
            ans = 0;
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n n s s ans = 0; ans 0 for(;;){
            n = sc.nextInt();
            s = sc.nextInt();
            if(n == 0 && s == 0) break;
            for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            }
            System.out.println(ans);
            ans = 0;
        } ; {
            n = sc.nextInt();
            s = sc.nextInt();
            if(n == 0 && s == 0) break;
            for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            }
            System.out.println(ans);
            ans = 0;
        } {
            n = sc.nextInt();
            s = sc.nextInt();
            if(n == 0 && s == 0) break;
            for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            }
            System.out.println(ans);
            ans = 0;
        } n = sc.nextInt() n sc.nextInt() sc.nextInt sc s = sc.nextInt() s sc.nextInt() sc.nextInt sc if(n == 0 && s == 0) break; n == 0 && s == 0 n == 0 n 0 s == 0 s 0 break; for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            } {
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            } for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                } int x = i+1; int x = i+1; x i+1 i 1 x < n x n x++ x++ x {
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                } {
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                } for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    } int y = x+1; int y = x+1; y x+1 x 1 y <= n y n y++ y++ y {
                        if(i+x+y==s) ans+=1;
                    } {
                        if(i+x+y==s) ans+=1;
                    } if(i+x+y==s) ans+=1; i+x+y==s i+x+y i+x+y i x y s ans+=1 ans 1 System.out.println(ans) System.out.println System.out System System.out ans ans = 0 ans 0 String[] args args public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, s, ans = 0;
 
        for(;;){
            n = sc.nextInt();
            s = sc.nextInt();
            if(n == 0 && s == 0) break;
            for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            }
            System.out.println(ans);
            ans = 0;
        }
    }
} public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, s, ans = 0;
 
        for(;;){
            n = sc.nextInt();
            s = sc.nextInt();
            if(n == 0 && s == 0) break;
            for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            }
            System.out.println(ans);
            ans = 0;
        }
    }
} Main
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, s, ans = 0;
 
        for(;;){
            n = sc.nextInt();
            s = sc.nextInt();
            if(n == 0 && s == 0) break;
            for(int i = 1; i < n; i++){
                for(int x = i+1; x < n; x++){
                    for(int y = x+1; y <= n; y++){
                        if(i+x+y==s) ans+=1;
                    }
                }
            }
            System.out.println(ans);
            ans = 0;
        }
    }
}