
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 && b == 0)
				break;
			int sum = 0;
			for (int i = 1; i <= a - 2; i++) {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			}
			System.out.println(sum);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 && b == 0)
				break;
			int sum = 0;
			for (int i = 1; i <= a - 2; i++) {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			}
			System.out.println(sum);
		}
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 && b == 0)
				break;
			int sum = 0;
			for (int i = 1; i <= a - 2; i++) {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			}
			System.out.println(sum);
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 && b == 0)
				break;
			int sum = 0;
			for (int i = 1; i <= a - 2; i++) {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			}
			System.out.println(sum);
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 && b == 0)
				break;
			int sum = 0;
			for (int i = 1; i <= a - 2; i++) {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			}
			System.out.println(sum);
		} true {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 && b == 0)
				break;
			int sum = 0;
			for (int i = 1; i <= a - 2; i++) {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			}
			System.out.println(sum);
		} int a = scanner.nextInt(); a scanner.nextInt() scanner.nextInt scanner int b = scanner.nextInt(); b scanner.nextInt() scanner.nextInt scanner if (a == 0 && b == 0)
				break; a == 0 && b == 0 a == 0 a 0 b == 0 b 0 break; int sum = 0; sum 0 for (int i = 1; i <= a - 2; i++) {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			} int i = 1; int i = 1; i 1 i <= a - 2 i a - 2 a 2 i++ i++ i {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			} {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			} for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				} int j = i + 1; int j = i + 1; j i + 1 i 1 j <= a - 1 j a - 1 a 1 j++ j++ j {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				} {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				} if (i + j > b)
						break; i + j > b i + j i j b break; for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					} int k = j + 1; int k = j + 1; k j + 1 j 1 k <= a k a k++ k++ k {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					} {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					} if (i + j + k > b)
							break; i + j + k > b i + j + k i + j + k i j k b break; if (i + j + k == b)
							sum++; i + j + k == b i + j + k i + j + k i j k b sum++ sum System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 && b == 0)
				break;
			int sum = 0;
			for (int i = 1; i <= a - 2; i++) {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			}
			System.out.println(sum);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 && b == 0)
				break;
			int sum = 0;
			for (int i = 1; i <= a - 2; i++) {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			}
			System.out.println(sum);
		}
	}
} Main

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 && b == 0)
				break;
			int sum = 0;
			for (int i = 1; i <= a - 2; i++) {
				for (int j = i + 1; j <= a - 1; j++) {
					if (i + j > b)
						break;
					for (int k = j + 1; k <= a; k++) {
						if (i + j + k > b)
							break;
						if (i + j + k == b)
							sum++;
					}
				}
			}
			System.out.println(sum);
		}
	}
}