import java.util.Scanner;

public class Main{

	static Scanner s=new Scanner(System.in);

	public static void main(String __[]){
		while(true) {
			input();
			if((n|x)==0)
				break;
			solve();
		}
	}

	static int n,x;
	private static void input(){
		n=s.nextInt();
		x=s.nextInt();
	}
	private static void solve(){
		long 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++;
				}
			}
		}
		System.out.println(count);
	}
} import java.util.Scanner; Scanner java.util public class Main{

	static Scanner s=new Scanner(System.in);

	public static void main(String __[]){
		while(true) {
			input();
			if((n|x)==0)
				break;
			solve();
		}
	}

	static int n,x;
	private static void input(){
		n=s.nextInt();
		x=s.nextInt();
	}
	private static void solve(){
		long 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++;
				}
			}
		}
		System.out.println(count);
	}
} Main static Scanner s=new Scanner(System.in); s new Scanner(System.in) static int n n x; x public static void main(String __[]){
		while(true) {
			input();
			if((n|x)==0)
				break;
			solve();
		}
	} main {
		while(true) {
			input();
			if((n|x)==0)
				break;
			solve();
		}
	} while(true) {
			input();
			if((n|x)==0)
				break;
			solve();
		} true {
			input();
			if((n|x)==0)
				break;
			solve();
		} input() input if((n|x)==0)
				break; (n|x)==0 (n|x) n x 0 break; solve() solve String __[] __ private static void input(){
		n=s.nextInt();
		x=s.nextInt();
	} input {
		n=s.nextInt();
		x=s.nextInt();
	} n=s.nextInt() n s.nextInt() s.nextInt s x=s.nextInt() x s.nextInt() s.nextInt s private static void solve(){
		long 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++;
				}
			}
		}
		System.out.println(count);
	} solve {
		long 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++;
				}
			}
		}
		System.out.println(count);
	} long 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 System.out.println(count) System.out.println System.out System System.out count public class Main{

	static Scanner s=new Scanner(System.in);

	public static void main(String __[]){
		while(true) {
			input();
			if((n|x)==0)
				break;
			solve();
		}
	}

	static int n,x;
	private static void input(){
		n=s.nextInt();
		x=s.nextInt();
	}
	private static void solve(){
		long 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++;
				}
			}
		}
		System.out.println(count);
	}
} public class Main{

	static Scanner s=new Scanner(System.in);

	public static void main(String __[]){
		while(true) {
			input();
			if((n|x)==0)
				break;
			solve();
		}
	}

	static int n,x;
	private static void input(){
		n=s.nextInt();
		x=s.nextInt();
	}
	private static void solve(){
		long 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++;
				}
			}
		}
		System.out.println(count);
	}
} Main
import java.util.Scanner;

public class Main{

	static Scanner s=new Scanner(System.in);

	public static void main(String __[]){
		while(true) {
			input();
			if((n|x)==0)
				break;
			solve();
		}
	}

	static int n,x;
	private static void input(){
		n=s.nextInt();
		x=s.nextInt();
	}
	private static void solve(){
		long 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++;
				}
			}
		}
		System.out.println(count);
	}
}