import java.util.Scanner;

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

		for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++;

		System.out.println(COUNT);
		
		}
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
		int n = sc.nextInt();
		int x = sc.nextInt();
		int COUNT = 0;
		
		if(n == 0 && x == 0)
				break;

		for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++;

		System.out.println(COUNT);
		
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
		int n = sc.nextInt();
		int x = sc.nextInt();
		int COUNT = 0;
		
		if(n == 0 && x == 0)
				break;

		for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++;

		System.out.println(COUNT);
		
		}
	} main {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
		int n = sc.nextInt();
		int x = sc.nextInt();
		int COUNT = 0;
		
		if(n == 0 && x == 0)
				break;

		for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++;

		System.out.println(COUNT);
		
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while(sc.hasNext()) {
		int n = sc.nextInt();
		int x = sc.nextInt();
		int COUNT = 0;
		
		if(n == 0 && x == 0)
				break;

		for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++;

		System.out.println(COUNT);
		
		} sc.hasNext() sc.hasNext sc {
		int n = sc.nextInt();
		int x = sc.nextInt();
		int COUNT = 0;
		
		if(n == 0 && x == 0)
				break;

		for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++;

		System.out.println(COUNT);
		
		} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int COUNT = 0; COUNT 0 if(n == 0 && x == 0)
				break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++; int a = 1; int a = 1; a 1 a < n+1 a n+1 n 1 a++ a++ a for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++; for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++; int b = a+1; int b = a+1; b a+1 a 1 b < n+1 b n+1 n 1 b++ b++ b for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++; for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++; int c = b+1; int c = b+1; c b+1 b 1 c < n+1 c n+1 n 1 c++ c++ c if (a+b+c == x)
						COUNT++; if (a+b+c == x)
						COUNT++; a+b+c == x a+b+c a+b+c a b c x COUNT++ COUNT 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) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
		int n = sc.nextInt();
		int x = sc.nextInt();
		int COUNT = 0;
		
		if(n == 0 && x == 0)
				break;

		for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++;

		System.out.println(COUNT);
		
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
		int n = sc.nextInt();
		int x = sc.nextInt();
		int COUNT = 0;
		
		if(n == 0 && x == 0)
				break;

		for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++;

		System.out.println(COUNT);
		
		}
	}
} Main
import java.util.Scanner;

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

		for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++;

		System.out.println(COUNT);
		
		}
	}
}

