public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		while(true){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int a,b,c = 1;
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}
			for(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
} public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		while(true){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int a,b,c = 1;
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}
			for(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
} Main public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		while(true){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int a,b,c = 1;
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}
			for(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		}
	} main {
		java.util.Scanner scan = new java.util.Scanner(System.in);
		while(true){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int a,b,c = 1;
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}
			for(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		}
	} java.util.Scanner scan = new java.util.Scanner(System.in); scan new java.util.Scanner(System.in) while(true){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int a,b,c = 1;
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}
			for(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		} true {
			int n = scan.nextInt();
			int x = scan.nextInt();
			int a,b,c = 1;
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}
			for(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan int a a b b c = 1; c 1 int 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(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			} a = 1; a = 1 a 1 a<=n a n a++ a++ a {
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			} {
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			} for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				} b = a; b = a b a b<=n b n b++ b++ b {
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				} {
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				} for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					} c = b; c = b c b c<=n c n c++ c++ c {
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					} {
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					} if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						} x == (a+b+c) && (a!=b) && (b!=c) && (c!=a) (b!=c) x == (a+b+c) && (a!=b) && (b!=c) && (c!=a) x == (a+b+c) x (a+b+c) a+b+c a b c (a!=b) a b (b!=c) b c (c!=a) c a {
							count ++;
							break;
						} count ++ count break; 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){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		while(true){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int a,b,c = 1;
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}
			for(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
} public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		while(true){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int a,b,c = 1;
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}
			for(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
} Main
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		while(true){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int a,b,c = 1;
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}
			for(a = 1;a<=n;a++){
				for(b = a;b<=n;b++){
					for(c = b;c<=n;c++){
						if(x == (a+b+c) && (a!=b) && (b!=c) && (c!=a)){
							count ++;
							break;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}