import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n,x,count=0;
	    int data[] = new int[100];
	    while(true){
	        n = sc.nextInt();
	        x = sc.nextInt();
	        if(n==0&&x==0)break;
	        for(int i=0;i<n;i++)data[i]=i+1;

	        for(int i=0;i<n-2;i++){
	            for(int j = i+1;j<n-1;j++){
	                for(int k=j+1;k<n;k++){
	                    if(x==data[i]+data[j]+data[k])count++;
	                }
	            }
	        }
	        System.out.println(count);
	        count=0;
	    }
	        sc.close();
	}
}
 import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n,x,count=0;
	    int data[] = new int[100];
	    while(true){
	        n = sc.nextInt();
	        x = sc.nextInt();
	        if(n==0&&x==0)break;
	        for(int i=0;i<n;i++)data[i]=i+1;

	        for(int i=0;i<n-2;i++){
	            for(int j = i+1;j<n-1;j++){
	                for(int k=j+1;k<n;k++){
	                    if(x==data[i]+data[j]+data[k])count++;
	                }
	            }
	        }
	        System.out.println(count);
	        count=0;
	    }
	        sc.close();
	}
} Main public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n,x,count=0;
	    int data[] = new int[100];
	    while(true){
	        n = sc.nextInt();
	        x = sc.nextInt();
	        if(n==0&&x==0)break;
	        for(int i=0;i<n;i++)data[i]=i+1;

	        for(int i=0;i<n-2;i++){
	            for(int j = i+1;j<n-1;j++){
	                for(int k=j+1;k<n;k++){
	                    if(x==data[i]+data[j]+data[k])count++;
	                }
	            }
	        }
	        System.out.println(count);
	        count=0;
	    }
	        sc.close();
	} main {
	    Scanner sc = new Scanner(System.in);
	    int n,x,count=0;
	    int data[] = new int[100];
	    while(true){
	        n = sc.nextInt();
	        x = sc.nextInt();
	        if(n==0&&x==0)break;
	        for(int i=0;i<n;i++)data[i]=i+1;

	        for(int i=0;i<n-2;i++){
	            for(int j = i+1;j<n-1;j++){
	                for(int k=j+1;k<n;k++){
	                    if(x==data[i]+data[j]+data[k])count++;
	                }
	            }
	        }
	        System.out.println(count);
	        count=0;
	    }
	        sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n n x x count=0; count 0 int data[] = new int[100]; data new int[100] 100 while(true){
	        n = sc.nextInt();
	        x = sc.nextInt();
	        if(n==0&&x==0)break;
	        for(int i=0;i<n;i++)data[i]=i+1;

	        for(int i=0;i<n-2;i++){
	            for(int j = i+1;j<n-1;j++){
	                for(int k=j+1;k<n;k++){
	                    if(x==data[i]+data[j]+data[k])count++;
	                }
	            }
	        }
	        System.out.println(count);
	        count=0;
	    } true {
	        n = sc.nextInt();
	        x = sc.nextInt();
	        if(n==0&&x==0)break;
	        for(int i=0;i<n;i++)data[i]=i+1;

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

	        for(int i=0;i<n-2;i++){
	            for(int j = i+1;j<n-1;j++){
	                for(int k=j+1;k<n;k++){
	                    if(x==data[i]+data[j]+data[k])count++;
	                }
	            }
	        }
	        System.out.println(count);
	        count=0;
	    }
	        sc.close();
	}
} public class Main{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n,x,count=0;
	    int data[] = new int[100];
	    while(true){
	        n = sc.nextInt();
	        x = sc.nextInt();
	        if(n==0&&x==0)break;
	        for(int i=0;i<n;i++)data[i]=i+1;

	        for(int i=0;i<n-2;i++){
	            for(int j = i+1;j<n-1;j++){
	                for(int k=j+1;k<n;k++){
	                    if(x==data[i]+data[j]+data[k])count++;
	                }
	            }
	        }
	        System.out.println(count);
	        count=0;
	    }
	        sc.close();
	}
} Main
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n,x,count=0;
	    int data[] = new int[100];
	    while(true){
	        n = sc.nextInt();
	        x = sc.nextInt();
	        if(n==0&&x==0)break;
	        for(int i=0;i<n;i++)data[i]=i+1;

	        for(int i=0;i<n-2;i++){
	            for(int j = i+1;j<n-1;j++){
	                for(int k=j+1;k<n;k++){
	                    if(x==data[i]+data[j]+data[k])count++;
	                }
	            }
	        }
	        System.out.println(count);
	        count=0;
	    }
	        sc.close();
	}
}

