import java.util.*;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner as = new Scanner(System.in);
		int n,x,i,j,k,t;
		int s = 0;
		String str;
		
		while(true){
			
			n = as.nextInt();
			x = as.nextInt();
			s=0;
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				}	
			}
			
			str=String.valueOf(s/6);
			System.out.println(str);
			
		}
		
		

	}

} import java.util.*; util.* java class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner as = new Scanner(System.in);
		int n,x,i,j,k,t;
		int s = 0;
		String str;
		
		while(true){
			
			n = as.nextInt();
			x = as.nextInt();
			s=0;
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				}	
			}
			
			str=String.valueOf(s/6);
			System.out.println(str);
			
		}
		
		

	}

} Main /**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner as = new Scanner(System.in);
		int n,x,i,j,k,t;
		int s = 0;
		String str;
		
		while(true){
			
			n = as.nextInt();
			x = as.nextInt();
			s=0;
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				}	
			}
			
			str=String.valueOf(s/6);
			System.out.println(str);
			
		}
		
		

	} main {
		// TODO Auto-generated method stub
		
		Scanner as = new Scanner(System.in);
		int n,x,i,j,k,t;
		int s = 0;
		String str;
		
		while(true){
			
			n = as.nextInt();
			x = as.nextInt();
			s=0;
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				}	
			}
			
			str=String.valueOf(s/6);
			System.out.println(str);
			
		}
		
		

	} Scanner as = new Scanner(System.in); as new Scanner(System.in) int n n x x i i j j k k t; t int s = 0; s 0 String str; str while(true){
			
			n = as.nextInt();
			x = as.nextInt();
			s=0;
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				}	
			}
			
			str=String.valueOf(s/6);
			System.out.println(str);
			
		} true {
			
			n = as.nextInt();
			x = as.nextInt();
			s=0;
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				}	
			}
			
			str=String.valueOf(s/6);
			System.out.println(str);
			
		} n = as.nextInt() n as.nextInt() as.nextInt as x = as.nextInt() x as.nextInt() as.nextInt as s=0 s 0 if(n == 0 && x == 0){
				break;
			} n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
				break;
			} break; for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				}	
			} i=1; i=1 i 1 i<=n i n i++ i++ i {
				for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				}	
			} {
				for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				}	
			} for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				} j=1; j=1 j 1 j<=n j n j++ j++ j {
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				} {
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				} for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					} k=1; k=1 k 1 k<=n k n k++ k++ k {
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					} {
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					} if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						} i != j && j != k && i != k i != j && j != k && i != k i != j i j j != k j k i != k i k {
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						} if((i+j+k) == x){
								
								s++;
								
							} (i+j+k) == x (i+j+k) i+j+k i j k x {
								
								s++;
								
							} s++ s str=String.valueOf(s/6) str String.valueOf(s/6) String.valueOf String s/6 s 6 System.out.println(str) System.out.println System.out System System.out str String[] args args
import java.util.*;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner as = new Scanner(System.in);
		int n,x,i,j,k,t;
		int s = 0;
		String str;
		
		while(true){
			
			n = as.nextInt();
			x = as.nextInt();
			s=0;
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i=1;i<=n;i++){
				for(j=1;j<=n;j++){
					for(k=1;k<=n;k++){
						
						if(i != j && j != k && i != k){
								
							if((i+j+k) == x){
								
								s++;
								
							}
								
						}
							
					}	
				}	
			}
			
			str=String.valueOf(s/6);
			System.out.println(str);
			
		}
		
		

	}

}