import java.util.Scanner;

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

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