import java.util.Scanner;


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


public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(;;)
		{
			int n = scanner.nextInt();
			int x = scanner.nextInt();
			
			int cnt = 0;
			if(n==0 && 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)
						{
							cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
		}
	}
}