import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int x=sc.nextInt();
			if(n==0){
				break;
			}
			System.out.println(result(n,x));
		}
	}

	public static int result(int n, int x){
		int count=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((i+j+k)==x){
						count++;
					}
				}
			}
		}
		return count;
	}


} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int x=sc.nextInt();
			if(n==0){
				break;
			}
			System.out.println(result(n,x));
		}
	}

	public static int result(int n, int x){
		int count=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((i+j+k)==x){
						count++;
					}
				}
			}
		}
		return count;
	}


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

	public static int result(int n, int x){
		int count=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((i+j+k)==x){
						count++;
					}
				}
			}
		}
		return count;
	}


} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int x=sc.nextInt();
			if(n==0){
				break;
			}
			System.out.println(result(n,x));
		}
	}

	public static int result(int n, int x){
		int count=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((i+j+k)==x){
						count++;
					}
				}
			}
		}
		return count;
	}


} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int x=sc.nextInt();
			if(n==0){
				break;
			}
			System.out.println(result(n,x));
		}
	}

	public static int result(int n, int x){
		int count=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((i+j+k)==x){
						count++;
					}
				}
			}
		}
		return count;
	}


}
