import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if (n == 0 && x == 0)
				break;
			System.out.println(run(n, x));
		}
		System.exit(0);
	}

	private static int run(int n, int x) {
		int result = 0;
		for (int a = 1; a <= n; a++)
			for (int b = a + 1; b <= n; b++)
				for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result;
		return (result);

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

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if (n == 0 && x == 0)
				break;
			System.out.println(run(n, x));
		}
		System.exit(0);
	}

	private static int run(int n, int x) {
		int result = 0;
		for (int a = 1; a <= n; a++)
			for (int b = a + 1; b <= n; b++)
				for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result;
		return (result);

	}
} Main public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if (n == 0 && x == 0)
				break;
			System.out.println(run(n, x));
		}
		System.exit(0);
	} main {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if (n == 0 && x == 0)
				break;
			System.out.println(run(n, x));
		}
		System.exit(0);
	} @SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in); scan new Scanner(System.in) while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if (n == 0 && x == 0)
				break;
			System.out.println(run(n, x));
		} true {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if (n == 0 && x == 0)
				break;
			System.out.println(run(n, x));
		} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int 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; System.out.println(run(n, x)) System.out.println System.out System System.out run(n, x) run n x System.exit(0) System.exit System 0 String[] args args private static int run(int n, int x) {
		int result = 0;
		for (int a = 1; a <= n; a++)
			for (int b = a + 1; b <= n; b++)
				for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result;
		return (result);

	} run {
		int result = 0;
		for (int a = 1; a <= n; a++)
			for (int b = a + 1; b <= n; b++)
				for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result;
		return (result);

	} int result = 0; result 0 for (int a = 1; a <= n; a++)
			for (int b = a + 1; b <= n; b++)
				for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result; int a = 1; int a = 1; a 1 a <= n a n a++ a++ a for (int b = a + 1; b <= n; b++)
				for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result; for (int b = a + 1; b <= n; b++)
				for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result; int b = a + 1; int b = a + 1; b a + 1 a 1 b <= n b n b++ b++ b for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result; for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result; int c = b + 1; int c = b + 1; c b + 1 b 1 c <= n c n c++ c++ c if (a + b + c == x)
						++result; if (a + b + c == x)
						++result; a + b + c == x a + b + c a + b + c a b c x ++result result return (result); (result) int n n int x x public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if (n == 0 && x == 0)
				break;
			System.out.println(run(n, x));
		}
		System.exit(0);
	}

	private static int run(int n, int x) {
		int result = 0;
		for (int a = 1; a <= n; a++)
			for (int b = a + 1; b <= n; b++)
				for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result;
		return (result);

	}
} public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if (n == 0 && x == 0)
				break;
			System.out.println(run(n, x));
		}
		System.exit(0);
	}

	private static int run(int n, int x) {
		int result = 0;
		for (int a = 1; a <= n; a++)
			for (int b = a + 1; b <= n; b++)
				for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result;
		return (result);

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		while (true) {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if (n == 0 && x == 0)
				break;
			System.out.println(run(n, x));
		}
		System.exit(0);
	}

	private static int run(int n, int x) {
		int result = 0;
		for (int a = 1; a <= n; a++)
			for (int b = a + 1; b <= n; b++)
				for (int c = b + 1; c <= n; c++)
					if (a + b + c == x)
						++result;
		return (result);

	}
}