#include <stdio.h>
int main(){

   int n, x, i ,j, k, s;
   
   scanf("%d %d", &n, &x);
   while (n != 0 || x != 0)
   {
   	s = 0;
   	for(i = 1; i <= n - 2; i++)
   	{
   		for(j = i + 1; j <= n - 1; j++)
   		{
   			for(k = j + 1; k <= n; k++)
   			{
   				if(i + j + k == x)
   				{
   					s++;
   				}
   			}
   		}
   	}
   	printf("%d", s);
   	scanf("%d %d", &n, &x);
   }
   return 0;
}