import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		}
	}
} import java.io.*; io.* java public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		}
	}
} Main public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		}
	} main {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		}
	} BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) while(true){
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		} true {
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		} String str = br.readLine(); str br.readLine() br.readLine br String[] i=str.split(" "); i str.split(" ") str.split str " " int n=Integer.parseInt(i[0]) n Integer.parseInt(i[0]) Integer.parseInt Integer i[0] i 0 x=Integer.parseInt(i[1]) x Integer.parseInt(i[1]) Integer.parseInt Integer i[1] i 1 count=0; count 0 if(n==0&&x==0){break;} n==0&&x==0 n==0 n 0 x==0 x 0 {break;} break; for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		} int a=1; int a=1; a 1 a<=n a n a++ a++ a {
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		} {
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		} for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			} int b=2; int b=2; b 2 b<=n b n b++ b++ b {
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			} {
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			} for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				} int c=3; int c=3; c 3 c<=n c n c++ c++ c {
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				} {
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				} if(a+b+c==x&&(a<b&&b<c)){count+=1;} a+b+c==x&&(a<b&&b<c) a+b+c==x a+b+c a+b+c a b c x (a<b&&b<c) a<b a b b<c b c {count+=1;} count+=1 count 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		}
	}
} public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		}
	}
} Main
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
		String str = br.readLine();
		String[] i=str.split(" ");
		int n=Integer.parseInt(i[0]),x=Integer.parseInt(i[1]),count=0;
		if(n==0&&x==0){break;}
		for (int a=1;a<=n;a++){
			for (int b=2;b<=n;b++){
				for(int c=3;c<=n;c++){
					if(a+b+c==x&&(a<b&&b<c)){count+=1;}
				}
			}
		}
		System.out.println(count);
		}
	}
}