import java.util.Scanner;

public class Main {

	private static Scanner sc;

	public static void main(String[] args){
		sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			int x=sc.nextInt();
			int a=0;
			if(n==0&&x==0)break;
			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){
							a=a+1;
							break;
						}
					}
				}
			}
			System.out.println(a);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	private static Scanner sc;

	public static void main(String[] args){
		sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			int x=sc.nextInt();
			int a=0;
			if(n==0&&x==0)break;
			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){
							a=a+1;
							break;
						}
					}
				}
			}
			System.out.println(a);
		}
	}
} Main private static Scanner sc; sc public static void main(String[] args){
		sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			int x=sc.nextInt();
			int a=0;
			if(n==0&&x==0)break;
			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){
							a=a+1;
							break;
						}
					}
				}
			}
			System.out.println(a);
		}
	} main {
		sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			int x=sc.nextInt();
			int a=0;
			if(n==0&&x==0)break;
			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){
							a=a+1;
							break;
						}
					}
				}
			}
			System.out.println(a);
		}
	} sc = new Scanner(System.in) sc new Scanner(System.in) while(true){
			int n=sc.nextInt();
			int x=sc.nextInt();
			int a=0;
			if(n==0&&x==0)break;
			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){
							a=a+1;
							break;
						}
					}
				}
			}
			System.out.println(a);
		} true {
			int n=sc.nextInt();
			int x=sc.nextInt();
			int a=0;
			if(n==0&&x==0)break;
			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){
							a=a+1;
							break;
						}
					}
				}
			}
			System.out.println(a);
		} int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int x=sc.nextInt(); x sc.nextInt() sc.nextInt sc int a=0; a 0 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-2;i++){
				for(int j=i+1;j<=n-1;j++){
					for(int k=j+1;k<=n;k++){
						if(i+j+k==x){
							a=a+1;
							break;
						}
					}
				}
			} 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){
							a=a+1;
							break;
						}
					}
				}
			} {
				for(int j=i+1;j<=n-1;j++){
					for(int k=j+1;k<=n;k++){
						if(i+j+k==x){
							a=a+1;
							break;
						}
					}
				}
			} for(int j=i+1;j<=n-1;j++){
					for(int k=j+1;k<=n;k++){
						if(i+j+k==x){
							a=a+1;
							break;
						}
					}
				} 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){
							a=a+1;
							break;
						}
					}
				} {
					for(int k=j+1;k<=n;k++){
						if(i+j+k==x){
							a=a+1;
							break;
						}
					}
				} for(int k=j+1;k<=n;k++){
						if(i+j+k==x){
							a=a+1;
							break;
						}
					} 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){
							a=a+1;
							break;
						}
					} {
						if(i+j+k==x){
							a=a+1;
							break;
						}
					} if(i+j+k==x){
							a=a+1;
							break;
						} i+j+k==x i+j+k i+j+k i j k x {
							a=a+1;
							break;
						} a=a+1 a a+1 a 1 break; System.out.println(a) System.out.println System.out System System.out a String[] args args public class Main {

	private static Scanner sc;

	public static void main(String[] args){
		sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			int x=sc.nextInt();
			int a=0;
			if(n==0&&x==0)break;
			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){
							a=a+1;
							break;
						}
					}
				}
			}
			System.out.println(a);
		}
	}
} public class Main {

	private static Scanner sc;

	public static void main(String[] args){
		sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			int x=sc.nextInt();
			int a=0;
			if(n==0&&x==0)break;
			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){
							a=a+1;
							break;
						}
					}
				}
			}
			System.out.println(a);
		}
	}
} Main
import java.util.Scanner;

public class Main {

	private static Scanner sc;

	public static void main(String[] args){
		sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			int x=sc.nextInt();
			int a=0;
			if(n==0&&x==0)break;
			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){
							a=a+1;
							break;
						}
					}
				}
			}
			System.out.println(a);
		}
	}
}