import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        while (true)
        {
        	String[] nx = br.readLine().split(" ");
            int n = Integer.parseInt(nx[0]);
            int x = Integer.parseInt(nx[1]);
            if(n == 0 && x == 0)
            	break;
            
            int count = 0;
            for (int i = 1; i <= n - 2; i++)
            {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            }
            System.out.println(count);
        }
        
		
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        while (true)
        {
        	String[] nx = br.readLine().split(" ");
            int n = Integer.parseInt(nx[0]);
            int x = Integer.parseInt(nx[1]);
            if(n == 0 && x == 0)
            	break;
            
            int count = 0;
            for (int i = 1; i <= n - 2; i++)
            {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            }
            System.out.println(count);
        }
        
		
	}

} Main public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        while (true)
        {
        	String[] nx = br.readLine().split(" ");
            int n = Integer.parseInt(nx[0]);
            int x = Integer.parseInt(nx[1]);
            if(n == 0 && x == 0)
            	break;
            
            int count = 0;
            for (int i = 1; i <= n - 2; i++)
            {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            }
            System.out.println(count);
        }
        
		
	} main {
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        while (true)
        {
        	String[] nx = br.readLine().split(" ");
            int n = Integer.parseInt(nx[0]);
            int x = Integer.parseInt(nx[1]);
            if(n == 0 && x == 0)
            	break;
            
            int count = 0;
            for (int i = 1; i <= n - 2; i++)
            {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            }
            System.out.println(count);
        }
        
		
	} InputStreamReader isr = new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader br = new BufferedReader(isr); br new BufferedReader(isr) while (true)
        {
        	String[] nx = br.readLine().split(" ");
            int n = Integer.parseInt(nx[0]);
            int x = Integer.parseInt(nx[1]);
            if(n == 0 && x == 0)
            	break;
            
            int count = 0;
            for (int i = 1; i <= n - 2; i++)
            {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            }
            System.out.println(count);
        } true {
        	String[] nx = br.readLine().split(" ");
            int n = Integer.parseInt(nx[0]);
            int x = Integer.parseInt(nx[1]);
            if(n == 0 && x == 0)
            	break;
            
            int count = 0;
            for (int i = 1; i <= n - 2; i++)
            {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            }
            System.out.println(count);
        } String[] nx = br.readLine().split(" "); nx br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(nx[0]); n Integer.parseInt(nx[0]) Integer.parseInt Integer nx[0] nx 0 int x = Integer.parseInt(nx[1]); x Integer.parseInt(nx[1]) Integer.parseInt Integer nx[1] nx 1 if(n == 0 && x == 0)
            	break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; int count = 0; count 0 for (int i = 1; i <= n - 2; i++)
            {
            	for (int j = i + 1; j <= n -1; 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 - 2 i n - 2 n 2 i++ i++ i {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            } {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            } for (int j = i + 1; j <= n -1; 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 -1 j n -1 n 1 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 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        while (true)
        {
        	String[] nx = br.readLine().split(" ");
            int n = Integer.parseInt(nx[0]);
            int x = Integer.parseInt(nx[1]);
            if(n == 0 && x == 0)
            	break;
            
            int count = 0;
            for (int i = 1; i <= n - 2; i++)
            {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            }
            System.out.println(count);
        }
        
		
	}

} public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        while (true)
        {
        	String[] nx = br.readLine().split(" ");
            int n = Integer.parseInt(nx[0]);
            int x = Integer.parseInt(nx[1]);
            if(n == 0 && x == 0)
            	break;
            
            int count = 0;
            for (int i = 1; i <= n - 2; i++)
            {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            }
            System.out.println(count);
        }
        
		
	}

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
        while (true)
        {
        	String[] nx = br.readLine().split(" ");
            int n = Integer.parseInt(nx[0]);
            int x = Integer.parseInt(nx[1]);
            if(n == 0 && x == 0)
            	break;
            
            int count = 0;
            for (int i = 1; i <= n - 2; i++)
            {
            	for (int j = i + 1; j <= n -1; j++)
            	{
            		for (int k = j + 1; k <= n; k++)
            		{
            			if ((i + j + k) == x)
            				count++;
            		}
            	}
            }
            System.out.println(count);
        }
        
		
	}

}