import java.util.*;
 
class Main{
    public static void main(String[] args){
		int n, x, cnt;
		Scanner scan = new Scanner(System.in);
		List<String> list = new ArrayList<String>();
        
		while(true){
			cnt = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n==0 && x==0){
				break;
			}

			int[] arr = new int[n];
			for(int i=0; i<n; i++){
				arr[i] = (i+1);
			}

			for(int i=0; i<n; i++){
				for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
		}
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
		int n, x, cnt;
		Scanner scan = new Scanner(System.in);
		List<String> list = new ArrayList<String>();
        
		while(true){
			cnt = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n==0 && x==0){
				break;
			}

			int[] arr = new int[n];
			for(int i=0; i<n; i++){
				arr[i] = (i+1);
			}

			for(int i=0; i<n; i++){
				for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
		}
    }
} Main public static void main(String[] args){
		int n, x, cnt;
		Scanner scan = new Scanner(System.in);
		List<String> list = new ArrayList<String>();
        
		while(true){
			cnt = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n==0 && x==0){
				break;
			}

			int[] arr = new int[n];
			for(int i=0; i<n; i++){
				arr[i] = (i+1);
			}

			for(int i=0; i<n; i++){
				for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
		}
    } main {
		int n, x, cnt;
		Scanner scan = new Scanner(System.in);
		List<String> list = new ArrayList<String>();
        
		while(true){
			cnt = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n==0 && x==0){
				break;
			}

			int[] arr = new int[n];
			for(int i=0; i<n; i++){
				arr[i] = (i+1);
			}

			for(int i=0; i<n; i++){
				for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
		}
    } int n n x x cnt; cnt Scanner scan = new Scanner(System.in); scan new Scanner(System.in) List<String> list = new ArrayList<String>(); list new ArrayList<String>() while(true){
			cnt = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n==0 && x==0){
				break;
			}

			int[] arr = new int[n];
			for(int i=0; i<n; i++){
				arr[i] = (i+1);
			}

			for(int i=0; i<n; i++){
				for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
		} true {
			cnt = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n==0 && x==0){
				break;
			}

			int[] arr = new int[n];
			for(int i=0; i<n; i++){
				arr[i] = (i+1);
			}

			for(int i=0; i<n; i++){
				for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
		} cnt = 0 cnt 0 n = scan.nextInt() n scan.nextInt() scan.nextInt scan x = scan.nextInt() x scan.nextInt() scan.nextInt scan if(n==0 && x==0){
				break;
			} n==0 && x==0 n==0 n 0 x==0 x 0 {
				break;
			} break; int[] arr = new int[n]; arr new int[n] n for(int i=0; i<n; i++){
				arr[i] = (i+1);
			} int i=0; int i=0; i 0 i<n i n i++ i++ i {
				arr[i] = (i+1);
			} {
				arr[i] = (i+1);
			} arr[i] = (i+1) arr[i] arr i (i+1) i 1 for(int i=0; i<n; i++){
				for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				}
			} int i=0; int i=0; i 0 i<n i n i++ i++ i {
				for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				}
			} {
				for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				}
			} for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				} 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((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				} {
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				} for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					} int k=j+1; int k=j+1; k j+1 j 1 k<n k n k++ k++ k {
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					} {
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					} if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						} (arr[i] + arr[j] + arr[k]) == x (arr[i] + arr[j] + arr[k]) arr[i] + arr[j] + arr[k] arr[i] arr i arr[j] arr j arr[k] arr k x {
							cnt++;
						} cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args
import java.util.*;
 
class Main{
    public static void main(String[] args){
		int n, x, cnt;
		Scanner scan = new Scanner(System.in);
		List<String> list = new ArrayList<String>();
        
		while(true){
			cnt = 0;
			n = scan.nextInt();
			x = scan.nextInt();
			if(n==0 && x==0){
				break;
			}

			int[] arr = new int[n];
			for(int i=0; i<n; i++){
				arr[i] = (i+1);
			}

			for(int i=0; i<n; i++){
				for(int j=i+1; j<n; j++){
					for(int k=j+1; k<n; k++){
						if((arr[i] + arr[j] + arr[k]) == x){
							cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
		}
    }
}