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;i++)
			{
				for(int j = i + 1;j <= n;j++)
				{
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				}
			}
			System.out.println(count);
			n = scan.nextInt();
			x = scan.nextInt();
			count = 0;
		}
	}
} 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;i++)
			{
				for(int j = i + 1;j <= n;j++)
				{
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				}
			}
			System.out.println(count);
			n = scan.nextInt();
			x = scan.nextInt();
			count = 0;
		}
	}
} 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;i++)
			{
				for(int j = i + 1;j <= n;j++)
				{
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				}
			}
			System.out.println(count);
			n = scan.nextInt();
			x = scan.nextInt();
			count = 0;
		}
	} 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;i++)
			{
				for(int j = i + 1;j <= n;j++)
				{
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				}
			}
			System.out.println(count);
			n = scan.nextInt();
			x = scan.nextInt();
			count = 0;
		}
	} 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;i++)
			{
				for(int j = i + 1;j <= n;j++)
				{
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				}
			}
			System.out.println(count);
			n = scan.nextInt();
			x = scan.nextInt();
			count = 0;
		} n != 0 || x != 0 n != 0 n 0 x != 0 x 0 {
			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){count++;}
					}
				}
			}
			System.out.println(count);
			n = scan.nextInt();
			x = scan.nextInt();
			count = 0;
		} 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){count++;}
					}
				}
			} 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){count++;}
					}
				}
			} {
				for(int j = i + 1;j <= n;j++)
				{
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				}
			} for(int j = i + 1;j <= n;j++)
				{
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				} 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){count++;}
					}
				} {
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				} for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					} 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){count++;}
					} {
						if(i + j + k == x){count++;}
					} if(i + j + k == x){count++;} i + j + k == x i + j + k i + j + k i j k x {count++;} count++ count System.out.println(count) System.out.println System.out System System.out count n = scan.nextInt() n scan.nextInt() scan.nextInt scan x = scan.nextInt() x scan.nextInt() scan.nextInt scan count = 0 count 0 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;i++)
			{
				for(int j = i + 1;j <= n;j++)
				{
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				}
			}
			System.out.println(count);
			n = scan.nextInt();
			x = scan.nextInt();
			count = 0;
		}
	}
} 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;i++)
			{
				for(int j = i + 1;j <= n;j++)
				{
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				}
			}
			System.out.println(count);
			n = scan.nextInt();
			x = scan.nextInt();
			count = 0;
		}
	}
} 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;i++)
			{
				for(int j = i + 1;j <= n;j++)
				{
					for(int k = j + 1;k <= n;k++)
					{
						if(i + j + k == x){count++;}
					}
				}
			}
			System.out.println(count);
			n = scan.nextInt();
			x = scan.nextInt();
			count = 0;
		}
	}
}