import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = new String[2];
		int n=0, x=0, count=0;
		ArrayList<Integer> result = new ArrayList<Integer>();
		while(true)
		{
			strs = br.readLine().split(" ");
			n = Integer.parseInt(strs[0]);
			x = Integer.parseInt(strs[1]);
			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)
						{
							count++;
						}
					}
				}
			}
			result.add(count);
			count = 0;
		}
		for(int cnt=0; cnt<result.size(); cnt++)
		{
			System.out.println(result.get(cnt));
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = new String[2];
		int n=0, x=0, count=0;
		ArrayList<Integer> result = new ArrayList<Integer>();
		while(true)
		{
			strs = br.readLine().split(" ");
			n = Integer.parseInt(strs[0]);
			x = Integer.parseInt(strs[1]);
			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)
						{
							count++;
						}
					}
				}
			}
			result.add(count);
			count = 0;
		}
		for(int cnt=0; cnt<result.size(); cnt++)
		{
			System.out.println(result.get(cnt));
		}
	}
} Main public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = new String[2];
		int n=0, x=0, count=0;
		ArrayList<Integer> result = new ArrayList<Integer>();
		while(true)
		{
			strs = br.readLine().split(" ");
			n = Integer.parseInt(strs[0]);
			x = Integer.parseInt(strs[1]);
			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)
						{
							count++;
						}
					}
				}
			}
			result.add(count);
			count = 0;
		}
		for(int cnt=0; cnt<result.size(); cnt++)
		{
			System.out.println(result.get(cnt));
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = new String[2];
		int n=0, x=0, count=0;
		ArrayList<Integer> result = new ArrayList<Integer>();
		while(true)
		{
			strs = br.readLine().split(" ");
			n = Integer.parseInt(strs[0]);
			x = Integer.parseInt(strs[1]);
			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)
						{
							count++;
						}
					}
				}
			}
			result.add(count);
			count = 0;
		}
		for(int cnt=0; cnt<result.size(); cnt++)
		{
			System.out.println(result.get(cnt));
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] strs = new String[2]; strs new String[2] 2 int n=0 n 0 x=0 x 0 count=0; count 0 ArrayList<Integer> result = new ArrayList<Integer>(); result new ArrayList<Integer>() while(true)
		{
			strs = br.readLine().split(" ");
			n = Integer.parseInt(strs[0]);
			x = Integer.parseInt(strs[1]);
			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)
						{
							count++;
						}
					}
				}
			}
			result.add(count);
			count = 0;
		} true {
			strs = br.readLine().split(" ");
			n = Integer.parseInt(strs[0]);
			x = Integer.parseInt(strs[1]);
			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)
						{
							count++;
						}
					}
				}
			}
			result.add(count);
			count = 0;
		} strs = br.readLine().split(" ") strs br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " n = Integer.parseInt(strs[0]) n Integer.parseInt(strs[0]) Integer.parseInt Integer strs[0] strs 0 x = Integer.parseInt(strs[1]) x Integer.parseInt(strs[1]) Integer.parseInt Integer strs[1] strs 1 if(n==0 && x==0)	break; n==0 && x==0 n==0 n 0 x==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)
						{
							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 result.add(count) result.add result count count = 0 count 0 for(int cnt=0; cnt<result.size(); cnt++)
		{
			System.out.println(result.get(cnt));
		} int cnt=0; int cnt=0; cnt 0 cnt<result.size() cnt result.size() result.size result cnt++ cnt++ cnt {
			System.out.println(result.get(cnt));
		} {
			System.out.println(result.get(cnt));
		} System.out.println(result.get(cnt)) System.out.println System.out System System.out result.get(cnt) result.get result cnt String[] args args public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = new String[2];
		int n=0, x=0, count=0;
		ArrayList<Integer> result = new ArrayList<Integer>();
		while(true)
		{
			strs = br.readLine().split(" ");
			n = Integer.parseInt(strs[0]);
			x = Integer.parseInt(strs[1]);
			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)
						{
							count++;
						}
					}
				}
			}
			result.add(count);
			count = 0;
		}
		for(int cnt=0; cnt<result.size(); cnt++)
		{
			System.out.println(result.get(cnt));
		}
	}
} public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = new String[2];
		int n=0, x=0, count=0;
		ArrayList<Integer> result = new ArrayList<Integer>();
		while(true)
		{
			strs = br.readLine().split(" ");
			n = Integer.parseInt(strs[0]);
			x = Integer.parseInt(strs[1]);
			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)
						{
							count++;
						}
					}
				}
			}
			result.add(count);
			count = 0;
		}
		for(int cnt=0; cnt<result.size(); cnt++)
		{
			System.out.println(result.get(cnt));
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = new String[2];
		int n=0, x=0, count=0;
		ArrayList<Integer> result = new ArrayList<Integer>();
		while(true)
		{
			strs = br.readLine().split(" ");
			n = Integer.parseInt(strs[0]);
			x = Integer.parseInt(strs[1]);
			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)
						{
							count++;
						}
					}
				}
			}
			result.add(count);
			count = 0;
		}
		for(int cnt=0; cnt<result.size(); cnt++)
		{
			System.out.println(result.get(cnt));
		}
	}
}