import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) break;
			
			int ways = 0;
			
			for(int i = 1; i <= a; i++){
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			}

			System.out.println(ways/6);
		}
		
		sc.close();
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) break;
			
			int ways = 0;
			
			for(int i = 1; i <= a; i++){
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			}

			System.out.println(ways/6);
		}
		
		sc.close();
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) break;
			
			int ways = 0;
			
			for(int i = 1; i <= a; i++){
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			}

			System.out.println(ways/6);
		}
		
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) break;
			
			int ways = 0;
			
			for(int i = 1; i <= a; i++){
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			}

			System.out.println(ways/6);
		}
		
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) break;
			
			int ways = 0;
			
			for(int i = 1; i <= a; i++){
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			}

			System.out.println(ways/6);
		} true {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) break;
			
			int ways = 0;
			
			for(int i = 1; i <= a; i++){
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			}

			System.out.println(ways/6);
		} int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc if(a == 0 && b == 0) break; a == 0 && b == 0 a == 0 a 0 b == 0 b 0 break; int ways = 0; ways 0 for(int i = 1; i <= a; i++){
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			} int i = 1; int i = 1; i 1 i <= a i a i++ i++ i {
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			} {
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			} for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				} int j = 1; int j = 1; j 1 j <= a j a j++ j++ j {
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				} {
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				} for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					} int k = 1; int k = 1; k 1 k <= a k a k++ k++ k {
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					} {
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					} if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						} 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) == b){
								ways++;
							}
						} if((i + j + k) == b){
								ways++;
							} (i + j + k) == b (i + j + k) i + j + k i j k b {
								ways++;
							} ways++ ways System.out.println(ways/6) System.out.println System.out System System.out ways/6 ways 6 sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) break;
			
			int ways = 0;
			
			for(int i = 1; i <= a; i++){
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			}

			System.out.println(ways/6);
		}
		
		sc.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) break;
			
			int ways = 0;
			
			for(int i = 1; i <= a; i++){
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			}

			System.out.println(ways/6);
		}
		
		sc.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) break;
			
			int ways = 0;
			
			for(int i = 1; i <= a; i++){
				for(int j = 1; j <= a; j++){
					for(int k = 1; k <= a; k++){
						if(i != j && j != k && i != k){
							if((i + j + k) == b){
								ways++;
							}
						}
					}
				}
			}

			System.out.println(ways/6);
		}
		
		sc.close();
	}

}