import java.util.Scanner;

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

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