import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while (true) {
			int n = stdIn.nextInt();
			int x = stdIn.nextInt();
			if((n+x) == 0)
				break;

			int count = 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 && i!=j && j!=k && k!=i)
							count++;
					}
				}
			}
			System.out.println(count);
		}
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while (true) {
			int n = stdIn.nextInt();
			int x = stdIn.nextInt();
			if((n+x) == 0)
				break;

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

			int count = 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 && i!=j && j!=k && k!=i)
							count++;
					}
				}
			}
			System.out.println(count);
		}
	} main {
		Scanner stdIn = new Scanner(System.in);
		while (true) {
			int n = stdIn.nextInt();
			int x = stdIn.nextInt();
			if((n+x) == 0)
				break;

			int count = 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 && i!=j && j!=k && k!=i)
							count++;
					}
				}
			}
			System.out.println(count);
		}
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) while (true) {
			int n = stdIn.nextInt();
			int x = stdIn.nextInt();
			if((n+x) == 0)
				break;

			int count = 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 && i!=j && j!=k && k!=i)
							count++;
					}
				}
			}
			System.out.println(count);
		} true {
			int n = stdIn.nextInt();
			int x = stdIn.nextInt();
			if((n+x) == 0)
				break;

			int count = 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 && i!=j && j!=k && k!=i)
							count++;
					}
				}
			}
			System.out.println(count);
		} int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int x = stdIn.nextInt(); x stdIn.nextInt() stdIn.nextInt stdIn if((n+x) == 0)
				break; (n+x) == 0 (n+x) n x 0 break; int count = 0; count 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 && i!=j && j!=k && k!=i)
							count++;
					}
				}
			} 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 && i!=j && j!=k && k!=i)
							count++;
					}
				}
			} {
				for (int j=i+1; j<=n-1; j++) {
					for (int k=j+1; k<=n; k++) {
						if((i+j+k) == x && i!=j && j!=k && k!=i)
							count++;
					}
				}
			} for (int j=i+1; j<=n-1; j++) {
					for (int k=j+1; k<=n; k++) {
						if((i+j+k) == x && i!=j && j!=k && k!=i)
							count++;
					}
				} 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 && i!=j && j!=k && k!=i)
							count++;
					}
				} {
					for (int k=j+1; k<=n; k++) {
						if((i+j+k) == x && i!=j && j!=k && k!=i)
							count++;
					}
				} for (int k=j+1; k<=n; k++) {
						if((i+j+k) == x && i!=j && j!=k && k!=i)
							count++;
					} 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 && i!=j && j!=k && k!=i)
							count++;
					} {
						if((i+j+k) == x && i!=j && j!=k && k!=i)
							count++;
					} if((i+j+k) == x && i!=j && j!=k && k!=i)
							count++; (i+j+k) == x && i!=j && j!=k && k!=i j!=k (i+j+k) == x && i!=j && j!=k && k!=i (i+j+k) == x (i+j+k) i+j+k i j k x i!=j i j j!=k j k k!=i k i count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while (true) {
			int n = stdIn.nextInt();
			int x = stdIn.nextInt();
			if((n+x) == 0)
				break;

			int count = 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 && i!=j && j!=k && k!=i)
							count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}