import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main (String args[]) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	StringBuffer buf =new StringBuffer();
    	int m,f;

    	    int[]c = new int[3];

    	 while(true){
     	    int n = sc.nextInt();
     	    int x = sc.nextInt();
     	    int count = 0;
    	    if(n==0&&x==0){
    	        break;

    	    }else{
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    }
    	    System.out.println(count);
    	 }


}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main (String args[]) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	StringBuffer buf =new StringBuffer();
    	int m,f;

    	    int[]c = new int[3];

    	 while(true){
     	    int n = sc.nextInt();
     	    int x = sc.nextInt();
     	    int count = 0;
    	    if(n==0&&x==0){
    	        break;

    	    }else{
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    }
    	    System.out.println(count);
    	 }


}
} Main public static void main (String args[]) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	StringBuffer buf =new StringBuffer();
    	int m,f;

    	    int[]c = new int[3];

    	 while(true){
     	    int n = sc.nextInt();
     	    int x = sc.nextInt();
     	    int count = 0;
    	    if(n==0&&x==0){
    	        break;

    	    }else{
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    }
    	    System.out.println(count);
    	 }


} main {
    	Scanner sc = new Scanner(System.in);
    	StringBuffer buf =new StringBuffer();
    	int m,f;

    	    int[]c = new int[3];

    	 while(true){
     	    int n = sc.nextInt();
     	    int x = sc.nextInt();
     	    int count = 0;
    	    if(n==0&&x==0){
    	        break;

    	    }else{
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    }
    	    System.out.println(count);
    	 }


} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuffer buf =new StringBuffer(); buf new StringBuffer() int m m f; f int[]c = new int[3]; c new int[3] 3 while(true){
     	    int n = sc.nextInt();
     	    int x = sc.nextInt();
     	    int count = 0;
    	    if(n==0&&x==0){
    	        break;

    	    }else{
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    }
    	    System.out.println(count);
    	 } true {
     	    int n = sc.nextInt();
     	    int x = sc.nextInt();
     	    int count = 0;
    	    if(n==0&&x==0){
    	        break;

    	    }else{
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    }
    	    System.out.println(count);
    	 } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int count = 0; count 0 if(n==0&&x==0){
    	        break;

    	    }else{
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    } n==0&&x==0 n==0 n 0 x==0 x 0 {
    	        break;

    	    } break; {
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    } for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    } int a=1; int a=1; a 1 a<=n a n a++ a++ a {
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    } {
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    } c[0]=a c[0] c 0 a for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	} int b=1; int b=1; b 1 b<=n b n b++ b++ b {
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	} {
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	} if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		} a<b a b {
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		} c[1]=b c[1] c 1 b for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			} int d=1; int d=1; d 1 d<=n d n d++ d++ d {
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			} {
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			} if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				} b<d b d {
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				} c[2]=d c[2] c 2 d if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					} c[0]+c[1]+c[2]==x c[0]+c[1]+c[2] c[0]+c[1]+c[2] c[0] c 0 c[1] c 1 c[2] c 2 x {
        	    						count +=1;
        	    					} count +=1 count 1 System.out.println(count) System.out.println System.out System System.out count String args[] args public class Main {
    public static void main (String args[]) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	StringBuffer buf =new StringBuffer();
    	int m,f;

    	    int[]c = new int[3];

    	 while(true){
     	    int n = sc.nextInt();
     	    int x = sc.nextInt();
     	    int count = 0;
    	    if(n==0&&x==0){
    	        break;

    	    }else{
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    }
    	    System.out.println(count);
    	 }


}
} public class Main {
    public static void main (String args[]) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	StringBuffer buf =new StringBuffer();
    	int m,f;

    	    int[]c = new int[3];

    	 while(true){
     	    int n = sc.nextInt();
     	    int x = sc.nextInt();
     	    int count = 0;
    	    if(n==0&&x==0){
    	        break;

    	    }else{
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    }
    	    System.out.println(count);
    	 }


}
} Main
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main (String args[]) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	StringBuffer buf =new StringBuffer();
    	int m,f;

    	    int[]c = new int[3];

    	 while(true){
     	    int n = sc.nextInt();
     	    int x = sc.nextInt();
     	    int count = 0;
    	    if(n==0&&x==0){
    	        break;

    	    }else{
    	    	for(int a=1;a<=n;a++){
        	    	c[0]=a;
        	    	for(int b=1;b<=n;b++){
        	    		if(a<b){
        	    			c[1]=b;
        	    			for(int d=1;d<=n;d++){
        	    				if(b<d){
        	    					c[2]=d;
        	    					if(c[0]+c[1]+c[2]==x){
        	    						count +=1;
        	    					}
        	    				}
        	    			}
        	    		}
        	    	}
        	    }
    	    }
    	    System.out.println(count);
    	 }


}
}