import java.util.Scanner;

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

public class Main{
    public static void main(String[] args){
        int i,j,k,x,n,co=0;
        Scanner s = new Scanner(System.in);
        while(true){
            n = s.nextInt();
            x = s.nextInt();
            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+k+j==x)co++;
                    }
                }
            }
            System.out.println(co);
            co =0;
        }
    }
}
