import java.util.Scanner;



public class Main{


	public static void main(String[] args){

		Scanner scan=new Scanner(System.in);

		while(true){
		int n=scan.nextInt();
		int x=scan.nextInt();

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

		System.out.println(return_num(n,x));

		}

		scan.close();
	}

	public static int return_num(int n, int x){
		int num=0;

		for(int i=1;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		}


	return num;
			}


} import java.util.Scanner; Scanner java.util public class Main{


	public static void main(String[] args){

		Scanner scan=new Scanner(System.in);

		while(true){
		int n=scan.nextInt();
		int x=scan.nextInt();

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

		System.out.println(return_num(n,x));

		}

		scan.close();
	}

	public static int return_num(int n, int x){
		int num=0;

		for(int i=1;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		}


	return num;
			}


} Main public static void main(String[] args){

		Scanner scan=new Scanner(System.in);

		while(true){
		int n=scan.nextInt();
		int x=scan.nextInt();

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

		System.out.println(return_num(n,x));

		}

		scan.close();
	} main {

		Scanner scan=new Scanner(System.in);

		while(true){
		int n=scan.nextInt();
		int x=scan.nextInt();

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

		System.out.println(return_num(n,x));

		}

		scan.close();
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) while(true){
		int n=scan.nextInt();
		int x=scan.nextInt();

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

		System.out.println(return_num(n,x));

		} true {
		int n=scan.nextInt();
		int x=scan.nextInt();

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

		System.out.println(return_num(n,x));

		} int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int 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; System.out.println(return_num(n,x)) System.out.println System.out System System.out return_num(n,x) return_num n x scan.close() scan.close scan String[] args args public static int return_num(int n, int x){
		int num=0;

		for(int i=1;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		}


	return num;
			} return_num {
		int num=0;

		for(int i=1;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		}


	return num;
			} int num=0; num 0 for(int i=1;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		} 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 k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		} {
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		} for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			} int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			} {
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			} for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				} int k=j+1; int k=j+1; k j+1 j 1 k<n+1 k n+1 n 1 k++ k++ k {
					if(i+j+k==x)num++;
				} {
					if(i+j+k==x)num++;
				} if(i+j+k==x)num++; i+j+k==x i+j+k i+j+k i j k x num++ num return num; num int n n int x x public class Main{


	public static void main(String[] args){

		Scanner scan=new Scanner(System.in);

		while(true){
		int n=scan.nextInt();
		int x=scan.nextInt();

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

		System.out.println(return_num(n,x));

		}

		scan.close();
	}

	public static int return_num(int n, int x){
		int num=0;

		for(int i=1;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		}


	return num;
			}


} public class Main{


	public static void main(String[] args){

		Scanner scan=new Scanner(System.in);

		while(true){
		int n=scan.nextInt();
		int x=scan.nextInt();

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

		System.out.println(return_num(n,x));

		}

		scan.close();
	}

	public static int return_num(int n, int x){
		int num=0;

		for(int i=1;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		}


	return num;
			}


} Main
import java.util.Scanner;



public class Main{


	public static void main(String[] args){

		Scanner scan=new Scanner(System.in);

		while(true){
		int n=scan.nextInt();
		int x=scan.nextInt();

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

		System.out.println(return_num(n,x));

		}

		scan.close();
	}

	public static int return_num(int n, int x){
		int num=0;

		for(int i=1;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				for(int k=j+1;k<n+1;k++){
					if(i+j+k==x)num++;
				}
			}
		}


	return num;
			}


}