import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n=stdIn.nextInt();
			int x=stdIn.nextInt();
			if(n==0)
				break;
			int ans=0;
			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)
							ans++;
					}
				}
			}
			System.out.println(ans);
		}
	}
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java import java.math.*; math.* java public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n=stdIn.nextInt();
			int x=stdIn.nextInt();
			if(n==0)
				break;
			int ans=0;
			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)
							ans++;
					}
				}
			}
			System.out.println(ans);
		}
	}
} Main public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n=stdIn.nextInt();
			int x=stdIn.nextInt();
			if(n==0)
				break;
			int ans=0;
			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)
							ans++;
					}
				}
			}
			System.out.println(ans);
		}
	} main {
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n=stdIn.nextInt();
			int x=stdIn.nextInt();
			if(n==0)
				break;
			int ans=0;
			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)
							ans++;
					}
				}
			}
			System.out.println(ans);
		}
	} Scanner stdIn=new Scanner(System.in); stdIn new Scanner(System.in) BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) while(true){
			int n=stdIn.nextInt();
			int x=stdIn.nextInt();
			if(n==0)
				break;
			int ans=0;
			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)
							ans++;
					}
				}
			}
			System.out.println(ans);
		} true {
			int n=stdIn.nextInt();
			int x=stdIn.nextInt();
			if(n==0)
				break;
			int ans=0;
			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)
							ans++;
					}
				}
			}
			System.out.println(ans);
		} int n=stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int x=stdIn.nextInt(); x stdIn.nextInt() stdIn.nextInt stdIn if(n==0)
				break; n==0 n 0 break; int ans=0; ans 0 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)
							ans++;
					}
				}
			} 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)
							ans++;
					}
				}
			} {
				for(int j=i+1;j<n;j++){
					for(int k=j+1;k<=n;k++){
						if(i+j+k==x)
							ans++;
					}
				}
			} for(int j=i+1;j<n;j++){
					for(int k=j+1;k<=n;k++){
						if(i+j+k==x)
							ans++;
					}
				} 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)
							ans++;
					}
				} {
					for(int k=j+1;k<=n;k++){
						if(i+j+k==x)
							ans++;
					}
				} for(int k=j+1;k<=n;k++){
						if(i+j+k==x)
							ans++;
					} 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)
							ans++;
					} {
						if(i+j+k==x)
							ans++;
					} if(i+j+k==x)
							ans++; i+j+k==x i+j+k i+j+k i j k x ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n=stdIn.nextInt();
			int x=stdIn.nextInt();
			if(n==0)
				break;
			int ans=0;
			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)
							ans++;
					}
				}
			}
			System.out.println(ans);
		}
	}
} public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n=stdIn.nextInt();
			int x=stdIn.nextInt();
			if(n==0)
				break;
			int ans=0;
			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)
							ans++;
					}
				}
			}
			System.out.println(ans);
		}
	}
} Main
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n=stdIn.nextInt();
			int x=stdIn.nextInt();
			if(n==0)
				break;
			int ans=0;
			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)
							ans++;
					}
				}
			}
			System.out.println(ans);
		}
	}
}