import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		while(true){
			String[] line =sc.nextLine().split(" ");
			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
		//break	
			if(n==0 && x==0){
				break;
			}
			System.out.println(sum(n,x));
		}					

	}
	public static int sum(int n,int x){
		int count=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<i;j++){
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			}
		}
		return count;
	}
} import java.util.*; util.* java class Main{
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		while(true){
			String[] line =sc.nextLine().split(" ");
			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
		//break	
			if(n==0 && x==0){
				break;
			}
			System.out.println(sum(n,x));
		}					

	}
	public static int sum(int n,int x){
		int count=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<i;j++){
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			}
		}
		return count;
	}
} Main public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		while(true){
			String[] line =sc.nextLine().split(" ");
			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
		//break	
			if(n==0 && x==0){
				break;
			}
			System.out.println(sum(n,x));
		}					

	} main {
		Scanner sc= new Scanner(System.in);
		while(true){
			String[] line =sc.nextLine().split(" ");
			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
		//break	
			if(n==0 && x==0){
				break;
			}
			System.out.println(sum(n,x));
		}					

	} Scanner sc= new Scanner(System.in); sc new Scanner(System.in) while(true){
			String[] line =sc.nextLine().split(" ");
			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
		//break	
			if(n==0 && x==0){
				break;
			}
			System.out.println(sum(n,x));
		} true {
			String[] line =sc.nextLine().split(" ");
			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
		//break	
			if(n==0 && x==0){
				break;
			}
			System.out.println(sum(n,x));
		} String[] line =sc.nextLine().split(" "); line sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int n = Integer.parseInt(line[0]); n Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int x = Integer.parseInt(line[1]); x Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 if(n==0 && x==0){
				break;
			} n==0 && x==0 n==0 n 0 x==0 x 0 {
				break;
			} break; System.out.println(sum(n,x)) System.out.println System.out System System.out sum(n,x) sum n x String[] args args public static int sum(int n,int x){
		int count=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<i;j++){
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			}
		}
		return count;
	} sum {
		int count=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<i;j++){
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			}
		}
		return count;
	} int count=0; count 0 for(int i=0;i<n;i++){
			for(int j=0;j<i;j++){
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			for(int j=0;j<i;j++){
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			}
		} {
			for(int j=0;j<i;j++){
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			}
		} for(int j=0;j<i;j++){
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			} int j=0; int j=0; j 0 j<i j i j++ j++ j {
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			} {
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			} for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				} int k=0; int k=0; k 0 k<j k j k++ k++ k {
					if(x-3==i+j+k){
						count=count+1;
					}
				} {
					if(x-3==i+j+k){
						count=count+1;
					}
				} if(x-3==i+j+k){
						count=count+1;
					} x-3==i+j+k x-3 x 3 i+j+k i+j+k i j k {
						count=count+1;
					} count=count+1 count count+1 count 1 return count; count int n n int x x
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		while(true){
			String[] line =sc.nextLine().split(" ");
			int n = Integer.parseInt(line[0]);
			int x = Integer.parseInt(line[1]);
		//break	
			if(n==0 && x==0){
				break;
			}
			System.out.println(sum(n,x));
		}					

	}
	public static int sum(int n,int x){
		int count=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<i;j++){
				for(int k=0;k<j;k++){
					if(x-3==i+j+k){
						count=count+1;
					}
				}
			}
		}
		return count;
	}
}