import java.util.Scanner;

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

        int i ,j ,k ,count;

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

            if(n == 0 && x == 0)break;

            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++;
                        }
                    }
                }
            }

            System.out.printf("%d\n",count);

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

        int i ,j ,k ,count;

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

            if(n == 0 && x == 0)break;

            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++;
                        }
                    }
                }
            }

            System.out.printf("%d\n",count);

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

        int i ,j ,k ,count;

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

            if(n == 0 && x == 0)break;

            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++;
                        }
                    }
                }
            }

            System.out.printf("%d\n",count);

        }
    } main {
        Scanner sc =  new Scanner(System.in);

        int i ,j ,k ,count;

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

            if(n == 0 && x == 0)break;

            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++;
                        }
                    }
                }
            }

            System.out.printf("%d\n",count);

        }
    } Scanner sc =  new Scanner(System.in); sc new Scanner(System.in) int i i j j k k count; count while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            count = 0;

            if(n == 0 && x == 0)break;

            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++;
                        }
                    }
                }
            }

            System.out.printf("%d\n",count);

        } true {
            int n = sc.nextInt();
            int x = sc.nextInt();
            count = 0;

            if(n == 0 && x == 0)break;

            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++;
                        }
                    }
                }
            }

            System.out.printf("%d\n",count);

        } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc count = 0 count 0 if(n == 0 && x == 0)break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; 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++ count System.out.printf("%d\n",count) System.out.printf System.out System System.out "%d\n" count String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc =  new Scanner(System.in);

        int i ,j ,k ,count;

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

            if(n == 0 && x == 0)break;

            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++;
                        }
                    }
                }
            }

            System.out.printf("%d\n",count);

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

        int i ,j ,k ,count;

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

            if(n == 0 && x == 0)break;

            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++;
                        }
                    }
                }
            }

            System.out.printf("%d\n",count);

        }
    }
} Main
import java.util.Scanner;

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

        int i ,j ,k ,count;

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

            if(n == 0 && x == 0)break;

            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++;
                        }
                    }
                }
            }

            System.out.printf("%d\n",count);

        }
    }
}
