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