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

public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
		
		for(;;)
		{
			String[] numberStr = input.readLine().split(" ");
			
			int max = Integer.parseInt(numberStr[0]);
			
			int sum = Integer.parseInt(numberStr[1]);
			
			if((max == 0)&&(sum == 0))
			{
				break;
			}
			
			int set = 0;
			
			for(int oneNum = 1; oneNum <= max - 2; oneNum++)
			{
				for(int twoNum = oneNum + 1; twoNum <= max + 1; twoNum++)
				{
					for(int threeNum = twoNum + 1; threeNum <= max; threeNum++)
					{
						if(oneNum + twoNum + threeNum == sum)
						{
							set++;
						}
					}
				}
			}
			
			System.out.println(set);
		}
	}
}


/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz