import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			int n=Integer.parseInt(in.next()),x=Integer.parseInt(in.next());
			if(n==0 && x==0)break;
			int cnt=0;
			for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			}
			out.println(cnt);
		}
		out.flush();
	}

} import java.util.*; util.* java import java.io.*; io.* java public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			int n=Integer.parseInt(in.next()),x=Integer.parseInt(in.next());
			if(n==0 && x==0)break;
			int cnt=0;
			for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			}
			out.println(cnt);
		}
		out.flush();
	}

} Main public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			int n=Integer.parseInt(in.next()),x=Integer.parseInt(in.next());
			if(n==0 && x==0)break;
			int cnt=0;
			for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			}
			out.println(cnt);
		}
		out.flush();
	} main {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			int n=Integer.parseInt(in.next()),x=Integer.parseInt(in.next());
			if(n==0 && x==0)break;
			int cnt=0;
			for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			}
			out.println(cnt);
		}
		out.flush();
	} Scanner in=new Scanner(System.in); in new Scanner(System.in) PrintWriter out=new PrintWriter(System.out); out new PrintWriter(System.out) while(true) {
			int n=Integer.parseInt(in.next()),x=Integer.parseInt(in.next());
			if(n==0 && x==0)break;
			int cnt=0;
			for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			}
			out.println(cnt);
		} true {
			int n=Integer.parseInt(in.next()),x=Integer.parseInt(in.next());
			if(n==0 && x==0)break;
			int cnt=0;
			for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			}
			out.println(cnt);
		} int n=Integer.parseInt(in.next()) n Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in x=Integer.parseInt(in.next()); x Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in if(n==0 && x==0)break; n==0 && x==0 n==0 n 0 x==0 x 0 break; int cnt=0; cnt 0 for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			} int i=1; int i=1; i 1 i<=n-2 i n-2 n 2 i++ i++ i {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			} {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			} for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				} int j=i+1; int j=i+1; j i+1 i 1 j<=n-1 j n-1 n 1 j++ j++ j {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				} {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				} for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					} 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)cnt++;
					} {
						if(i+j+k==x)cnt++;
					} if(i+j+k==x)cnt++; i+j+k==x i+j+k i+j+k i j k x cnt++ cnt out.println(cnt) out.println out cnt out.flush() out.flush out String[] args args public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			int n=Integer.parseInt(in.next()),x=Integer.parseInt(in.next());
			if(n==0 && x==0)break;
			int cnt=0;
			for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			}
			out.println(cnt);
		}
		out.flush();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			int n=Integer.parseInt(in.next()),x=Integer.parseInt(in.next());
			if(n==0 && x==0)break;
			int cnt=0;
			for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			}
			out.println(cnt);
		}
		out.flush();
	}

} Main
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			int n=Integer.parseInt(in.next()),x=Integer.parseInt(in.next());
			if(n==0 && x==0)break;
			int cnt=0;
			for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)cnt++;
					}
				}
			}
			out.println(cnt);
		}
		out.flush();
	}

}
