import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

			solve(n, x);
		}
	}
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void solve(int n, int x) {
		int ans = 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) ans++;
				}
			}
		}
		System.out.println(ans);
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(true) {
			int n, x;
			n = in.nextInt();
			x = in.nextInt();
			if(n == 0) break;

			solve(n, x);
		}
	}
} Main public static void solve(int n, int x) {
		int ans = 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) ans++;
				}
			}
		}
		System.out.println(ans);
	} solve {
		int ans = 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) ans++;
				}
			}
		}
		System.out.println(ans);
	} int ans = 0; ans 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) ans++;
				}
			}
		} 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) ans++;
				}
			}
		} {
			for(int j=i+1;j<=n-1;j++) {
				for(int k=j+1;k<=n;k++) {
					if(i+j+k==x) ans++;
				}
			}
		} for(int j=i+1;j<=n-1;j++) {
				for(int k=j+1;k<=n;k++) {
					if(i+j+k==x) ans++;
				}
			} 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) ans++;
				}
			} {
				for(int k=j+1;k<=n;k++) {
					if(i+j+k==x) ans++;
				}
			} for(int k=j+1;k<=n;k++) {
					if(i+j+k==x) ans++;
				} 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) ans++;
				} {
					if(i+j+k==x) ans++;
				} if(i+j+k==x) ans++; i+j+k==x i+j+k i+j+k i j k x ans++ ans System.out.println(ans) System.out.println System.out System System.out ans int n n int x x public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(true) {
			int n, x;
			n = in.nextInt();
			x = in.nextInt();
			if(n == 0) break;

			solve(n, x);
		}
	} main {
		Scanner in = new Scanner(System.in);
		while(true) {
			int n, x;
			n = in.nextInt();
			x = in.nextInt();
			if(n == 0) break;

			solve(n, x);
		}
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) while(true) {
			int n, x;
			n = in.nextInt();
			x = in.nextInt();
			if(n == 0) break;

			solve(n, x);
		} true {
			int n, x;
			n = in.nextInt();
			x = in.nextInt();
			if(n == 0) break;

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

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

			solve(n, x);
		}
	}
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

			solve(n, x);
		}
	}
}