import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner (System.in);
		while(sc.hasNextInt()){
			int n=sc.nextInt();
			int sum=sc.nextInt();
			if(n==0&&sum==0)break;
			int count=0;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		}
	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner (System.in);
		while(sc.hasNextInt()){
			int n=sc.nextInt();
			int sum=sc.nextInt();
			if(n==0&&sum==0)break;
			int count=0;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc=new Scanner (System.in);
		while(sc.hasNextInt()){
			int n=sc.nextInt();
			int sum=sc.nextInt();
			if(n==0&&sum==0)break;
			int count=0;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		}
	} main {
		Scanner sc=new Scanner (System.in);
		while(sc.hasNextInt()){
			int n=sc.nextInt();
			int sum=sc.nextInt();
			if(n==0&&sum==0)break;
			int count=0;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		}
	} Scanner sc=new Scanner (System.in); sc new Scanner (System.in) while(sc.hasNextInt()){
			int n=sc.nextInt();
			int sum=sc.nextInt();
			if(n==0&&sum==0)break;
			int count=0;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		} sc.hasNextInt() sc.hasNextInt sc {
			int n=sc.nextInt();
			int sum=sc.nextInt();
			if(n==0&&sum==0)break;
			int count=0;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		} int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int sum=sc.nextInt(); sum sc.nextInt() sc.nextInt sc if(n==0&&sum==0)break; n==0&&sum==0 n==0 n 0 sum==0 sum 0 break; int count=0; count 0 for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				}
			} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
				for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				}
			} {
				for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				}
			} for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				} int j=1; int j=1; j 1 j<=n j n j++ j++ j {
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				} {
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				} for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					} int k=1; int k=1; k 1 k<=n k n k++ k++ k {
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					} {
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					} if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						} i+j+k==sum&&i!=j&&j!=k&&i!=k j!=k i+j+k==sum&&i!=j&&j!=k&&i!=k i+j+k==sum i+j+k i+j+k i j k sum i!=j i j j!=k j k i!=k i k {
							count++;
						} count++ count System.out.println(count/6) System.out.println System.out System System.out count/6 count 6 String[] args args
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner (System.in);
		while(sc.hasNextInt()){
			int n=sc.nextInt();
			int sum=sc.nextInt();
			if(n==0&&sum==0)break;
			int count=0;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					for(int k=1;k<=n;k++){
						if(i+j+k==sum&&i!=j&&j!=k&&i!=k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		}
	}
}