import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;


public class Main {
    public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        int n,x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0){
                break;
            }
            result(n,x);
        }
    }
    
    public static void result(int n,int x){
        int sum = 0;
        for(int i = 1;i != n - 1;i++){
            for(int j = i + 1;j != n;j++){
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            }
        }
        System.out.println(sum);
    }
} import java.io.*; io.* java import java.util.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util public class Main {
    public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        int n,x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0){
                break;
            }
            result(n,x);
        }
    }
    
    public static void result(int n,int x){
        int sum = 0;
        for(int i = 1;i != n - 1;i++){
            for(int j = i + 1;j != n;j++){
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            }
        }
        System.out.println(sum);
    }
} Main public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        int n,x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0){
                break;
            }
            result(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;
            }
            result(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;
            }
            result(n,x);
        } true {
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0){
                break;
            }
            result(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;
            } break; result(n,x) result n x String[] args args public static void result(int n,int x){
        int sum = 0;
        for(int i = 1;i != n - 1;i++){
            for(int j = i + 1;j != n;j++){
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            }
        }
        System.out.println(sum);
    } result {
        int sum = 0;
        for(int i = 1;i != n - 1;i++){
            for(int j = i + 1;j != n;j++){
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            }
        }
        System.out.println(sum);
    } int sum = 0; sum 0 for(int i = 1;i != n - 1;i++){
            for(int j = i + 1;j != n;j++){
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            }
        } 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 I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            }
        } {
            for(int j = i + 1;j != n;j++){
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            }
        } for(int j = i + 1;j != n;j++){
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j != n j n j++ j++ j {
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            } {
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            } for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                } int I = j + 1; int I = j + 1; I j + 1 j 1 I != n + 1 I n + 1 n 1 I++ I++ I {
                    if(i + j + I == x){
                        sum++;
                    }
                } {
                    if(i + j + I == x){
                        sum++;
                    }
                } if(i + j + I == x){
                        sum++;
                    } i + j + I == x i + j + I i + j + I i j I x {
                        sum++;
                    } sum++ sum System.out.println(sum) System.out.println System.out System System.out sum int n n int x x public class Main {
    public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        int n,x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0){
                break;
            }
            result(n,x);
        }
    }
    
    public static void result(int n,int x){
        int sum = 0;
        for(int i = 1;i != n - 1;i++){
            for(int j = i + 1;j != n;j++){
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            }
        }
        System.out.println(sum);
    }
} public class Main {
    public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        int n,x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0){
                break;
            }
            result(n,x);
        }
    }
    
    public static void result(int n,int x){
        int sum = 0;
        for(int i = 1;i != n - 1;i++){
            for(int j = i + 1;j != n;j++){
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            }
        }
        System.out.println(sum);
    }
} Main
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;


public class Main {
    public static void main(String[] args)throws Exception{
        Scanner scan = new Scanner(System.in);
        int n,x;
        while(true){
            n = scan.nextInt();
            x = scan.nextInt();
            if(n == 0 && x == 0){
                break;
            }
            result(n,x);
        }
    }
    
    public static void result(int n,int x){
        int sum = 0;
        for(int i = 1;i != n - 1;i++){
            for(int j = i + 1;j != n;j++){
                for(int I = j + 1;I != n + 1;I++){
                    if(i + j + I == x){
                        sum++;
                    }
                }
            }
        }
        System.out.println(sum);
    }
}
