import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int x = scan.nextInt();
		int count=0;
		 while(true) {
		     count = 0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		}

		System.out.println(count);
		n = scan.nextInt();
		x = scan.nextInt();
		if(n == 0 && x == 0) break;
		}
		scan.close();
	}

}
 import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int x = scan.nextInt();
		int count=0;
		 while(true) {
		     count = 0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		}

		System.out.println(count);
		n = scan.nextInt();
		x = scan.nextInt();
		if(n == 0 && x == 0) break;
		}
		scan.close();
	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int x = scan.nextInt();
		int count=0;
		 while(true) {
		     count = 0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		}

		System.out.println(count);
		n = scan.nextInt();
		x = scan.nextInt();
		if(n == 0 && x == 0) break;
		}
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int x = scan.nextInt();
		int count=0;
		 while(true) {
		     count = 0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		}

		System.out.println(count);
		n = scan.nextInt();
		x = scan.nextInt();
		if(n == 0 && x == 0) break;
		}
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan int count=0; count 0 while(true) {
		     count = 0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		}

		System.out.println(count);
		n = scan.nextInt();
		x = scan.nextInt();
		if(n == 0 && x == 0) break;
		} true {
		     count = 0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		}

		System.out.println(count);
		n = scan.nextInt();
		x = scan.nextInt();
		if(n == 0 && x == 0) break;
		} count = 0 count 0 for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		} 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 h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		} {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		} for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			} int j=i+1; int j=i+1; j i+1 i 1 j<=n j n j++ j++ j {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			} {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			} for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				} int h=j+1; int h=j+1; h j+1 j 1 h<=n h n h++ h++ h {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				} {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				} if(x ==i+j+h )count ++; x ==i+j+h x i+j+h i+j+h i j h count ++ count System.out.println(count) System.out.println System.out System System.out count n = scan.nextInt() n scan.nextInt() scan.nextInt scan x = scan.nextInt() x scan.nextInt() scan.nextInt scan if(n == 0 && x == 0) break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int x = scan.nextInt();
		int count=0;
		 while(true) {
		     count = 0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		}

		System.out.println(count);
		n = scan.nextInt();
		x = scan.nextInt();
		if(n == 0 && x == 0) break;
		}
		scan.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int x = scan.nextInt();
		int count=0;
		 while(true) {
		     count = 0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		}

		System.out.println(count);
		n = scan.nextInt();
		x = scan.nextInt();
		if(n == 0 && x == 0) break;
		}
		scan.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int x = scan.nextInt();
		int count=0;
		 while(true) {
		     count = 0;
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				for(int h=j+1;h<=n;h++) {
					if(x ==i+j+h )count ++;
					//System.out.println(i + " " + j + " " +h);
				}
			}
		}

		System.out.println(count);
		n = scan.nextInt();
		x = scan.nextInt();
		if(n == 0 && x == 0) break;
		}
		scan.close();
	}

}

