//HowManyWays? ???????????°????????????????????§???
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int n,x,i,j,k,num;	//num????????????????????????????????????????????°???????´????????????°
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		x = in.nextInt();
		
		while(n != 0){
			num =0;
			
			//????????§????????????????????????????????????
			for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			}
			
			System.out.println(num/6);	//3! = 6??????????????????????????§6??§??????
			n = in.nextInt();
			x = in.nextInt();
		}
		
		in.close();
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		int n,x,i,j,k,num;	//num????????????????????????????????????????????°???????´????????????°
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		x = in.nextInt();
		
		while(n != 0){
			num =0;
			
			//????????§????????????????????????????????????
			for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			}
			
			System.out.println(num/6);	//3! = 6??????????????????????????§6??§??????
			n = in.nextInt();
			x = in.nextInt();
		}
		
		in.close();
	}
} Main public static void main(String[] args){
		int n,x,i,j,k,num;	//num????????????????????????????????????????????°???????´????????????°
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		x = in.nextInt();
		
		while(n != 0){
			num =0;
			
			//????????§????????????????????????????????????
			for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			}
			
			System.out.println(num/6);	//3! = 6??????????????????????????§6??§??????
			n = in.nextInt();
			x = in.nextInt();
		}
		
		in.close();
	} main {
		int n,x,i,j,k,num;	//num????????????????????????????????????????????°???????´????????????°
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		x = in.nextInt();
		
		while(n != 0){
			num =0;
			
			//????????§????????????????????????????????????
			for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			}
			
			System.out.println(num/6);	//3! = 6??????????????????????????§6??§??????
			n = in.nextInt();
			x = in.nextInt();
		}
		
		in.close();
	} int n n x x i i j j k k num; num Scanner in = new Scanner(System.in); in new Scanner(System.in) n = in.nextInt() n in.nextInt() in.nextInt in x = in.nextInt() x in.nextInt() in.nextInt in while(n != 0){
			num =0;
			
			//????????§????????????????????????????????????
			for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			}
			
			System.out.println(num/6);	//3! = 6??????????????????????????§6??§??????
			n = in.nextInt();
			x = in.nextInt();
		} n != 0 n 0 {
			num =0;
			
			//????????§????????????????????????????????????
			for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			}
			
			System.out.println(num/6);	//3! = 6??????????????????????????§6??§??????
			n = in.nextInt();
			x = in.nextInt();
		} num =0 num 0 for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			} i=1; i=1 i 1 i<=n i n i++ i++ i {
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			} {
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			} for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				} j=1; j=1 j 1 j<=n j n j++ j++ j {
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				} {
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				} if(j==i){continue;} j==i j i {continue;} continue; for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					} k=1; k=1 k 1 k<=n k n k++ k++ k {
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					} {
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					} if(k==i || k==j){continue;} k==i || k==j k==i k i k==j k j {continue;} continue; if(i+j+k == x){
							num++;
						} i+j+k == x i+j+k i+j+k i j k x {
							num++;
						} num++ num System.out.println(num/6) System.out.println System.out System System.out num/6 num 6 n = in.nextInt() n in.nextInt() in.nextInt in x = in.nextInt() x in.nextInt() in.nextInt in in.close() in.close in String[] args args public class Main{
	public static void main(String[] args){
		int n,x,i,j,k,num;	//num????????????????????????????????????????????°???????´????????????°
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		x = in.nextInt();
		
		while(n != 0){
			num =0;
			
			//????????§????????????????????????????????????
			for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			}
			
			System.out.println(num/6);	//3! = 6??????????????????????????§6??§??????
			n = in.nextInt();
			x = in.nextInt();
		}
		
		in.close();
	}
} public class Main{
	public static void main(String[] args){
		int n,x,i,j,k,num;	//num????????????????????????????????????????????°???????´????????????°
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		x = in.nextInt();
		
		while(n != 0){
			num =0;
			
			//????????§????????????????????????????????????
			for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			}
			
			System.out.println(num/6);	//3! = 6??????????????????????????§6??§??????
			n = in.nextInt();
			x = in.nextInt();
		}
		
		in.close();
	}
} Main
//HowManyWays? ???????????°????????????????????§???
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int n,x,i,j,k,num;	//num????????????????????????????????????????????°???????´????????????°
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		x = in.nextInt();
		
		while(n != 0){
			num =0;
			
			//????????§????????????????????????????????????
			for(i=1; i<=n; i++){
				for(j=1; j<=n; j++){
					if(j==i){continue;}
					for(k=1; k<=n; k++){
						if(k==i || k==j){continue;}
						if(i+j+k == x){
							num++;
						}
					}
				}
			}
			
			System.out.println(num/6);	//3! = 6??????????????????????????§6??§??????
			n = in.nextInt();
			x = in.nextInt();
		}
		
		in.close();
	}
}