import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		int n,x,m=0;
		int a[] = new int[256];

		Scanner scan = new Scanner(System.in);

		while(true)
		{
			int cnt=0;
			n = scan.nextInt();
			x = scan.nextInt();

			if( (n|x) == 0) break;

			for(int i=1; i<=n; i++)
			{
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			}

			a[m++] = cnt;
		}

		scan.close();

		for(int i=0; i<m; i++) System.out.println(a[i]);
	}
} import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String[] args) {

		int n,x,m=0;
		int a[] = new int[256];

		Scanner scan = new Scanner(System.in);

		while(true)
		{
			int cnt=0;
			n = scan.nextInt();
			x = scan.nextInt();

			if( (n|x) == 0) break;

			for(int i=1; i<=n; i++)
			{
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			}

			a[m++] = cnt;
		}

		scan.close();

		for(int i=0; i<m; i++) System.out.println(a[i]);
	}
} Main public static void main(String[] args) {

		int n,x,m=0;
		int a[] = new int[256];

		Scanner scan = new Scanner(System.in);

		while(true)
		{
			int cnt=0;
			n = scan.nextInt();
			x = scan.nextInt();

			if( (n|x) == 0) break;

			for(int i=1; i<=n; i++)
			{
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			}

			a[m++] = cnt;
		}

		scan.close();

		for(int i=0; i<m; i++) System.out.println(a[i]);
	} main {

		int n,x,m=0;
		int a[] = new int[256];

		Scanner scan = new Scanner(System.in);

		while(true)
		{
			int cnt=0;
			n = scan.nextInt();
			x = scan.nextInt();

			if( (n|x) == 0) break;

			for(int i=1; i<=n; i++)
			{
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			}

			a[m++] = cnt;
		}

		scan.close();

		for(int i=0; i<m; i++) System.out.println(a[i]);
	} int n n x x m=0; m 0 int a[] = new int[256]; a new int[256] 256 Scanner scan = new Scanner(System.in); scan new Scanner(System.in) while(true)
		{
			int cnt=0;
			n = scan.nextInt();
			x = scan.nextInt();

			if( (n|x) == 0) break;

			for(int i=1; i<=n; i++)
			{
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			}

			a[m++] = cnt;
		} true {
			int cnt=0;
			n = scan.nextInt();
			x = scan.nextInt();

			if( (n|x) == 0) break;

			for(int i=1; i<=n; i++)
			{
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			}

			a[m++] = cnt;
		} int cnt=0; cnt 0 n = scan.nextInt() n scan.nextInt() scan.nextInt scan x = scan.nextInt() x scan.nextInt() scan.nextInt scan if( (n|x) == 0) break; (n|x) == 0 (n|x) n x 0 break; for(int i=1; i<=n; i++)
			{
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			} {
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			} for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				} int j=i+1; int j=i+1; j i+1 i 1 j<=n j n j++ j++ j {
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				} {
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				} for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					} 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)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					} {
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					} if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						} i+j+k == x i+j+k i+j+k i j k x {
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						} cnt++ cnt a[m++] = cnt a[m++] a m++ m cnt scan.close() scan.close scan for(int i=0; i<m; i++) System.out.println(a[i]); int i=0; int i=0; i 0 i<m i m i++ i++ i System.out.println(a[i]); System.out.println(a[i]) System.out.println System.out System System.out a[i] a i String[] args args public class Main{

	public static void main(String[] args) {

		int n,x,m=0;
		int a[] = new int[256];

		Scanner scan = new Scanner(System.in);

		while(true)
		{
			int cnt=0;
			n = scan.nextInt();
			x = scan.nextInt();

			if( (n|x) == 0) break;

			for(int i=1; i<=n; i++)
			{
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			}

			a[m++] = cnt;
		}

		scan.close();

		for(int i=0; i<m; i++) System.out.println(a[i]);
	}
} public class Main{

	public static void main(String[] args) {

		int n,x,m=0;
		int a[] = new int[256];

		Scanner scan = new Scanner(System.in);

		while(true)
		{
			int cnt=0;
			n = scan.nextInt();
			x = scan.nextInt();

			if( (n|x) == 0) break;

			for(int i=1; i<=n; i++)
			{
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			}

			a[m++] = cnt;
		}

		scan.close();

		for(int i=0; i<m; i++) System.out.println(a[i]);
	}
} Main
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		int n,x,m=0;
		int a[] = new int[256];

		Scanner scan = new Scanner(System.in);

		while(true)
		{
			int cnt=0;
			n = scan.nextInt();
			x = scan.nextInt();

			if( (n|x) == 0) break;

			for(int i=1; i<=n; i++)
			{
				for(int j=i+1; j<=n; j++)
				{
					for(int k=j+1; k<=n; k++)
					{
						if(i+j+k == x)
						{
							//System.out.printf("%d %d %d\n", i, j, k);
							cnt++;
						}
					}
				}
			}

			a[m++] = cnt;
		}

		scan.close();

		for(int i=0; i<m; i++) System.out.println(a[i]);
	}
}