import java.util.Scanner;

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

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